-
Notifications
You must be signed in to change notification settings - Fork 45
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
Method for updating Entity not designed for using ManyToMany annotation #30
Comments
Here is a possible fix for the ZfcUserAdmin\Form\CreateUser: Remove the Zend\Stdlib\Hydrator\ClassMethods inside createAction of UserAdminController in l. 51:
Set the hydrator inside the onBootstrap method of Module.php:
The User entity must have the add and remove methods:
This fix allows storing the ManyToMany entities. Unfortunately this will not work for the ZfcUserAdmin\Form\EditUser because there is no hydrator passed inside the editAction. |
Here is a fix for saving ManyToMany entities using the ZfcUserAdmin\Form\EditUser: Service/User.php l. 78 ff.
Unfortunately the additional data from form is no longer added. We need a new setter process here. |
Correcting myself: |
Summary: Except: There is an issue about these naming conventions in ZfcUser which would solve this problem: If these naming conventions are accepted then extending the forms should follow them: |
Listed below are some issues that may relate or help to solve this topic. Custom hydration for User entity requested here: Using hydrators: Using different hydrators than ClassMethods: |
Are there any plans for refactoring the update process for an edit form to make it work? |
If the ZfcAdmin module will merge the zfcuser_user_hydrator option should we implement this feature to ZfcUserAdmin? Adapting the hydrator on the CreateUser and EditUser form should fix this and other issues, @Danielss89 |
Was wondering, does this mean that ManyToMany relationship won't work with current version? I have some problems where hydration doesn't seem to work and the ArrayCollection returned to entity is always empty, although the data is set inside form and form is valid. Is this related? Edit:Just tried out and I'm getting similar error inside UnitOfWork.php for Edit action. |
Hi @tad3j , regarding my issues I think nothing has changed. I believe @Danielss89 is very busy. Some of my issues are about a year old. But since a lot of things happened with At least for some of my issues there seems to be a fix using the Please tell me if this works for you. |
Hey @webdevilopers, thanks for your reply. I've noticed that this issue is old, and yes, was thinking the same. I think they are re-factoring ZfcUSer, so that might be the cause this module isn't moving forward. I've tried the code but I'm still experiencing the same problems (Hydrator doesn't hydrate ManyToMany select element and I get an error when submitting the edit form). So unfortunately it doesn't. :/ |
Guess it's best to wait for the next versions. BTW: what error did you get? |
I think I'm getting the same error as you (on edit form):
it's just that it's on line 1388. Edit: I've found out why this is happening...In my case ObjectSelect gets hydrated as a number(string) that's why error is thrown when we try to flush that. Temporary solution is to manually find references to those ids and re-add those custom objects/entites. |
@webdevilopers, have you tried to use |
I am extending my User entity with an attribute using a ManyToMany association.
In my example I use "costCenters" but you can think of it as the already existing "roles" attribute.
User entity:
Extending the form in my _Module.php_:
I already inserted some rows in my database and the edit form is populated correctely with these existing costcenters.
When editing and saving I get these warnings / errors:
Warning: spl_object_hash() expects parameter 1 to be object, string given in /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php on line 1375*
exception 'Doctrine\ORM\ORMException' with message 'Found entity of type on association Application\Entity\User#costCenters, but expecting Application\Entity\CostCenter' in /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:783
I think the configuration of entities and form are correct. It looks like the method to update the user entity in Service/User.php l. 78 ff. causes a problem:
My posted value for costCenters will be an array of strings including the IDs.
It looks like the entity manager will ony receive these strings since it doesn't know they have to be "hydrated" to find the related objects / entities.
Normally I would bind the object to Zend_Form and then a hydrator will do this in order to correctely persist the entity, e.g.:
Since saving multiple roles will probably be a use case for future admin forms can we achieve a solution here?
The text was updated successfully, but these errors were encountered: