I have a form for an entity that is by design potentially the target of many different types of relations; let's name it ManyTargetClass. Currently this ManyTargetClass is the inverse side of those relations using bidirectional relations. I can't change the fact that this class is the target of many relations. But I thought it doesn't look very good to have a bidirectional relationship for all the possible types of relations as it pollutes my ManyTargetClass with lots of inverse-side fields as well as their getters and setters and all this.
(Or is it normal?)
I am currently mitigating this with traits to reduce the visual clutter but I am not entirely happy with it, even though there are actual use-cases for reuse of those traits.
So I thought it would be better to have my RelatingClass1, RelatingClass2,... declare a unidirectional ManyToOne-relation to ManyTargetClass to get rid of the complexity on the inverse side.
But I failed to find a way to incorporate that into my form workflow when I want to go the unidirectional route. Remark that the RelatingClassX-classes are never created on their own.
They are always created via embedded forms in forms for other classes. This finally leads to my actual problem.
I want to create a ManyTargetClass-instance with embedded Forms that let me create RelationClassX-instances, automatically setting the ManyTargetClass-entity currently being created as target for the unidirectional relation established by the RelatinClassX-entity being created (preferable not having to lift potentially existing non-nullable-constraints on the join-column-definition of the RelationgClassX-side, if that is not possible I can lift this constraint though).
Is that possible? If yes: is it advisable and how would I do it?
question from:
https://stackoverflow.com/questions/65841935/symfony-form-how-to-set-the-entity-being-created-as-target-for-new-unidirection 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…