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

Creating entities #24

Open
waghanza opened this issue Nov 9, 2018 · 9 comments
Open

Creating entities #24

waghanza opened this issue Nov 9, 2018 · 9 comments

Comments

@waghanza
Copy link

waghanza commented Nov 9, 2018

Hi @paknahad,

I can see that ValidatorTrait validate fields using doctrine fields name, is not accurate to use getAttributeHydrator return fields

if ($validExistance && ! $metadata->hasField($field)) {

I mean, when I create object (POST on /book in my https://github.com/waghanza/book-manager), fields (in data on my json) are validated according to what doctrine know, not what hydratator know

Regards,

@paknahad
Copy link
Owner

Hi @waghanza

This bundle makes the hydrator's fields based on doctrine fields, so both of them are same.
Once you need to change the field name in hydrator, you can set the "validExistance" equal false and write a validator based on your needs.

@waghanza
Copy link
Author

Hi,

@paknahad Where could you set validExistance to false ?

Regards,

@paknahad
Copy link
Owner

paknahad commented Nov 11, 2018

in this line
https://github.com/waghanza/book-manager/blob/7158bf8d6e9a76f9aaec138178b62ee265fb284c/src/JsonApi/Hydrator/Book/AbstractBookHydrator.php#L66
you can pass "false" to validator like this:

$this->validateFields($this->objectManager->getClassMetadata(Book::class), $request, false);

@waghanza
Copy link
Author

but in this case the field type could not determined in

$validator = $this->getValidator($metadata->getTypeOfField($field));

@paknahad
Copy link
Owner

yeah. on changing the name of a field( or adding a field to hydrator which doesn't exist in the entity), you can't expect to validate automatically. so I wrote in my first comment, you must validate this fields by a custom validator.

@waghanza
Copy link
Author

but how we can add our custom validator ?

@paknahad
Copy link
Owner

In generated AbstractHydrator at the "validateRequest" method, after or instead of this line
https://github.com/waghanza/book-manager/blob/7158bf8d6e9a76f9aaec138178b62ee265fb284c/src/JsonApi/Hydrator/Book/AbstractBookHydrator.php#L66

actually, you are able to change any line of generated codes based on your needs

@waghanza
Copy link
Author

@paknahad I see, but how about having generators that could be customized ? I mean instead creating something like a custom recipe

For example, we can use a optional param to make:api to specify a template folder, with already customized template

What do you think ?

@paknahad
Copy link
Owner

Sounds nice. but I'm so busy currently. if you could implement this feature, I would be glad to merge your PR.

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

2 participants