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

Form element of inverse side of a bidirectional association is always removed #741

Open
diniciacci opened this issue Jun 29, 2023 · 5 comments

Comments

@diniciacci
Copy link

When a form is built from annotations (or attributes) if the form has an element that is an association, the element is removed from the form if it is on the inverse side of the association.

In case of a truly bidirectional (many-to-many) association implemented with best practices as suggested in https://gist.github.com/Ocramius/3121916 one might want to have forms generated from annotations (or attributes) to have the associated element on both sides i.e. also on the inverse side.

Currently EntityBasedFormBuilder checks to exclude an element here that triggers handleExcludeAssociation and this just checks if the element is the inverse side, and in that case, as a consequence, removes the element from the $formSpec.

This should be configurable, maybe with an appropriate annotation, ending up in the $metadata, that can be checked in the handleExcludeAssociation().

The annotation can be something like "bidirectional", to not mix the term with words like 'required', 'force' or 'keep'.

@TomHAnderson
Copy link
Member

Would detaching the handleExcludeAssociation do the job you're asking for?

$this->listeners[] = $events->attach(

@diniciacci
Copy link
Author

diniciacci commented Jul 11, 2023

Yes it should, but if I'm not wrong then unidirectional associations will get the element included too.
I.e. Removing the listener has a global effect on the form generation.
I.e. I can't easily remove it and re-add it during a single form generation

The common case is a composed form that has a bidirectional association and also contains another association that is unidirectional. If i remove the listener then both association will be included instead of just one.

In case of single form generation: removing, generating a form, re-adding workflow also looks a bit cumbersome to me.

I.e. IMHO the solution should be specific and not global. There should be a way to specify to not exclude an association (that is correctly excluded by default).

@TomHAnderson
Copy link
Member

I agree a specific solution is in order. So there are two options.

  1. change the whole library to suit your specific need (hasn't been raised before)
  2. detach the default listener and attach your own custom listener that looks for your specific use case.

I much prefer 2

@diniciacci
Copy link
Author

Dear Tom, not sure I get the point of you "answer".

I reported a use case that is not covered by the library and also a use case where detaching the listener would not work and has no reasonable workaround. Hence, to me, the request to support form generation of bidirectional associations look reasonable and not a corner case of my specific implementation.

To sum up the current status of the library:

  1. form generation of a form containing one or more many-to-many bidirectional associations is not supported by default. Workaround is to detach the listener and re-attach it afterwards.
  2. form generation of a form containing one or more many-to-many bidirectional associations and one or more many-to-many unidirectional associations is not supported and there is no workaround.

Do we agree on this or I am misunderstanding something?

@TomHAnderson
Copy link
Member

This issue requires a lot of framework to duplicate the issue. I would appreciate it if you'd provide a working application that duplicates this issue.

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