Symfony could only result in the plural-to-one sales (elizabeth.grams. regarding labels possessions to your addTag() method) to have English terminology. Password printed in another vocabulary wouldn’t behave as requested.
To save new labels that have Doctrine, you should think a few even more some thing. Very first, if you don’t iterate over-all of one’s the brand new Mark items and you will phone call $entityManager->persist($tag) on each, you’ll get an error out of Philosophy:
To solve which, you may choose to «cascade» the persist procedure instantly in the Activity object to your associated labels. To do this, add the cascade solution to your own ManyToMany metadata:
- Annotations
- YAML
- XML
A second potential topic works closely with the newest Getting Side and Inverse Side of Dple, if your «owning» section of the matchmaking try «Task», following perseverance is guaranteed to work since the labels are properly added towards the Task. However, if the running top is found on «Tag», then you will should do a little bit more strive to ensure that the best area of the dating was altered.
The secret is always to make sure brand new solitary «Task» is decided on every «Tag». One method to accomplish that is to try to add some most logic to help you addTag() , which is sometimes called because of the mode type of while the from the_reference is decided in order to untrue :
Allowing Labels to get Eliminated
The next thing is to allow brand new deletion regarding a certain items in the collection. The solution is like allowing tags to get added.
Theme Variations
The latest ensure it is_remove alternative ensures that if a piece of a collection is not delivered toward submitting, this new associated data is taken from the newest range to the server. In order for that it to work in a keen HTML means, you need to remove the DOM ability towards range item so you can come off, ahead of entry the form.
When a tag means is completely removed from the DOM and you will registered, brand new eliminated Tag target will not be within the range passed so you can setTags() . According to the work level, this might or might not be adequate to in fact remove the matchmaking within eliminated Tag and you may Task object.
When deleting stuff like this, you may have to do a little a bit more strive to ensure that the relationships between your Task and the got rid of Level are safely eliminated.
Typically in this instance you will have a plenty-to-that relationships and the removed tags will go away and you may persevere truthfully (adding brand new labels together with functions without difficulty).
But if you provides a one-to-of several matchmaking otherwise a quite a few-to-of many connection with a good mappedBy into the Activity entity (meaning Task is the «inverse» side), you will need to create a great deal more work for the fresh removed labels to help you persevere truthfully.
In this case, you could potentially modify the operator to get rid of the relationship for the got rid of mark. So it assumes which you have particular modify() step that is dealing with «update» of your own Task:
As you can tell, including and you can removing the elements correctly is going to be problematic. If you don’t enjoys a plenty-to-of several relationships where Task ‘s the «owning» front side, you’ll need to do extra work to ensure that the fresh matchmaking try properly current (whether you are adding the new labels or removing current tags) for each Level target itself.
The fresh Symfony people has created some JavaScript bundles that provide brand new effectiveness must create, edit and you will erase components of the brand new range. Read the /symfony-collection package to possess modern married secrets ne demek internet explorer and the symfony-range package centered on jQuery for the remainder of internet browsers.
You must do one another addTag() and you will removeTag() actions, if not the proper execution often nevertheless play with setTag() even if by_site try not true . You’ll find out more about new removeTag() strategy later in this article.