Problem with setting the default value for a ManyToOne relation but only when used in livecomponent with livecollection #2241
Replies: 3 comments 2 replies
-
Do you already made it work with a standard CollectionType ? |
Beta Was this translation helpful? Give feedback.
-
same issue here, the data option is not working when using the addCollectionItem |
Beta Was this translation helpful? Give feedback.
-
Had the same issue. In the symfony slack channel someone suggested to override the
to
A bit cumbersome to have to override this function but it does work. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an entity "Main" which has a OneToMany relation named "children" to the entity "Child".
Inside the "Child" there is a ManyToOne relation named "other" to another entity named "Related".
When a new child is created I want to set a default value for the relation "other".
I can't do it in the constructor of the entity because I would need the entitymanager for that.
I can't use a factory class, because I want to use this in a livecomponent with a livecollection
and there the creation of the objects is done internally.
So I do it via the data option in the formtype for child:
This does work in a normal form
but does not work in a live component with a live collection.
Since the live collection does all the work internally when creating/adding a new child,
I don't know how or where I can initialize the child.other relation property!
Is this the expected behaviour? What am I doing wrong? Can someone help?
Reproducer:
live-collection-reproducer-zip.zip
Beta Was this translation helpful? Give feedback.
All reactions