Symfony can only result in the plural-to-just one transformation (elizabeth.grams. regarding tags assets into the addTag() method) to possess English terms and conditions. Code written in various other code would not act as asked.
To keep the fresh new labels which have Philosophy, you will want to imagine one or two a lot more something. Basic, if you do not iterate over-all of the new Mark stuff and you will label $entityManager->persist($tag) on every, you will get a mistake out of Philosophy:
To resolve which, you could potentially “cascade” this new persist operation immediately throughout the Task object to the associated tags. To achieve this, add the cascade solution to your ManyToMany metadata:
- Annotations
- YAML
- XML
One minute potential procedure works with new Running Side and Inverse Edge of Dple, if your “owning” area of the matchmaking is actually “Task”, next work works since the labels was safely extra towards the Activity. Although not, if your owning side is on “Tag”, then you’ll must do a little more strive to ensure that the proper side of the matchmaking is changed.
The trick is to try to guarantee that new solitary “Task” is determined for each “Tag”. One good way to do that would be to add some more reason so you can addTag() , called by setting method of because the by_resource is set to help you not the case :
Allowing Tags as Removed
The next step is so that the deletion out of a specific product on the range. The clear answer is like making it possible for labels to be extra.
Template Improvement
The brand new make it_erase choice means that if the some a collection is not sent to the entry, the fresh related data is taken out of the fresh new range into server. To make sure that that it working in the an HTML function, you should eliminate the DOM feature to the collection items so you can go off, just before distribution the proper execution.
Whenever a tag function is taken away on DOM and you may registered, the new eliminated Mark target won’t be within the collection enacted so you can setTags() . Depending on your own effort layer, this could otherwise may possibly not be adequate to indeed eliminate the relationship between your removed Mark and Task target.
When removing stuff such as this, you may need to do some bit more work to make sure the dating between the Task as well as the removed Level was securely removed.
Generally in this instance https://www.datingranking.net/tr/wamba-inceleme/ you’ll have a plenty-to-one dating therefore the deleted tags will disappear and you will persist precisely (adding the brand new labels together with work effortlessly).
But if you have a one-to-of a lot matchmaking otherwise a quite a few-to-of a lot connection with an excellent mappedBy to your Task entity (meaning Activity is the “inverse” side), you will need to do a great deal more work for this new eliminated labels so you’re able to persevere correctly.
In this case, you might customize the control to get rid of the partnership into the eliminated level. Which assumes on you have some modify() step that is dealing with “update” of your own Task:
Clearly, adding and you will deleting the sun and rain truthfully are problematic. If you don’t enjoys a plenty of-to-many relationship in which Activity ‘s the “owning” front side, you’ll want to manage most strive to make sure the relationships try safely upgraded (whether you are adding brand new tags or removing existing labels) on every Level target alone.
New Symfony neighborhood has generated certain JavaScript packages giving the abilities had a need to include, edit and you will erase components of brand new collection. Read the /symfony-collection plan having progressive internet explorer and symfony-collection package according to jQuery for the rest of web browsers.
You have got to would one another addTag() and you may removeTag() steps, if not the design tend to nevertheless play with setTag() no matter if by the_site are not true . You’ll find out more and more the latest removeTag() strategy later in this article.
Leave a Reply