Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create entities with dependencies #2

Open
weierophinney opened this issue Dec 31, 2019 · 3 comments
Open

Unable to create entities with dependencies #2

weierophinney opened this issue Dec 31, 2019 · 3 comments

Comments

@weierophinney
Copy link
Contributor

Right now it's not possibile to create entities with dependencies. It's possibile to use the Instantatior but it's not aware of data on creation, so it's not possible if you have something like this:

class User
{
    public function __constructor(string $name)
    {
        $this->name = $name;
    }
}

Of course we could instantiate the entity with an empty string, but it's not the right way and things will be more complicated when a dependecy is needed (imagine a Role).

Should be useful another event that will allow to create entity based on POST data.


Originally posted by @thomasvargiu at zfcampus/zf-apigility-doctrine#313

@weierophinney
Copy link
Contributor Author

You're wrong. https://github.com/zfcampus/zf-apigility-doctrine/blob/master/src/Server/Resource/DoctrineResourceFactory.php#L102

You can create your own type of instantiator called an Entity Factory to create your entities. If you create a proper Entity Factory it will have access to the request or whatever else you inject it with.


Originally posted by @TomHAnderson at zfcampus/zf-apigility-doctrine#313 (comment)

@weierophinney
Copy link
Contributor Author

Ok. Thank you. The only thing is that I have no access to filtered data or I should call it two times.


Originally posted by @thomasvargiu at zfcampus/zf-apigility-doctrine#313 (comment)

@weierophinney
Copy link
Contributor Author

It will be up to you to configure your Entity Factory. If you need to fetch filtered data you'll probably have to fetch it explicitly in your factory rather than waiting for it to roll around to the resource method.


Originally posted by @TomHAnderson at zfcampus/zf-apigility-doctrine#313 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant