Answer the question
In order to leave comments, you need to log in
Symfony removes unnecessary ManyToMany associations when using a filter. How to win?
I'm using Symfony 3.3
. I have 2 tables (Entity) User and Project with a standard relationship @ORM\ManyToMany
In the standard form of the standard controller, the user can select checkboxes to have relationships between User and the list of filtered Projects (not all are displayed).
For filtering I use the successor SQLFilter (the same filter uses SoftDeleteable).
The problem is that if you uncheck the last checkbox, then all links from the database are deleted, including those that were filtered and were not displayed in the list.
This query is launched:
instead of the usual queryDELETE FROM user_project WHERE user_id = ?
DELETE FROM user_project WHERE user_id = ? AND project_id = ?
$builder->get('projects')
->addModelTransformer(new CallbackTransformer(...
Answer the question
In order to leave comments, you need to log in
It was solved very simply)
It was necessary to set the form property 'by_reference' => false, after which the removal method from my Entity (passed to the form) began to be used, and not automatically. Moreover, this property, according to the documentation, should seem to influence the use of the methods of the associated entity, and not the one passed to the form. Instead of PersistentCollection, an ArrayCollection was passed to the transformer, apparently from my getter.
There is a mention of this here (the main topic is that relationships are not saved):
https://afilina.com/doctrine-not-saving-manytomany
However, the issue of attaching a filter to a DELETE request is still relevant. To make sure your data is protected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question