Symfony are only able to make the plural-to-only one transformation (age.grams. on tags property towards addTag() method) to possess English terminology. Password written in other vocabulary won’t behave as asked.
To store the new labels which have Doctrine, you should believe a couple of significantly more things. Basic, unless you iterate over-all of the newest Tag items and you will phone call $entityManager->persist($tag) on every, you get a blunder off Doctrine:
To fix so it, you may choose to “cascade” the persist process automatically on Activity target manhunt to almost any related tags. To take action, range from the cascade option to the ManyToMany metadata:
- Annotations
- YAML
- XML
Another prospective topic works closely with new Purchasing Front side and Inverse Side of Dple, should your “owning” side of the relationship are “Task”, then work works given that labels try securely additional into Task. not, in case your possessing front is found on “Tag”, then you’ll have to do more work to make sure the correct area of the matchmaking try altered.
The trick is to try to make certain that the new single “Task” is decided on every “Tag”. One method to do this would be to then add even more reasoning in order to addTag() , to create from the mode types of as the because of the_site is decided to help you false :
Allowing Labels is Got rid of
The next step is so that the new deletion regarding a particular items on collection. The solution is much like enabling tags to-be extra.
Template Variations
The fresh allow_remove choice implies that if the an article of a collection is not delivered towards entry, the latest associated info is taken out of the collection on the servers. So as that this to operate when you look at the an HTML function, you need to remove the DOM element on the range goods to help you go off, before distribution the proper execution.
When a label function is removed regarding DOM and you will registered, the fresh removed Tag object may not be included in the collection passed to help you setTags() . Depending on the work coating, this might otherwise might not be sufficient to in reality remove the dating between the got rid of Level and you can Activity target.
When deleting things along these lines, you might have to perform some bit more strive to ensure that the relationships amongst the Task as well as the eliminated Level are safely removed.
Generally speaking in this situation you have a quite a few-to-one dating additionally the erased tags will go away and you may persevere precisely (including brand new tags as well as performs effortlessly).
But if you features a one-to-many dating or a lots of-to-of several relationship with good mappedBy toward Activity entity (definition Task ‘s the “inverse” side), you will need to perform way more benefit the fresh removed tags so you’re able to persevere truthfully.
In this case, you could modify the operator to eradicate the relationship on the eliminated tag. This assumes on which you have particular edit() action which is dealing with “update” of Task:
As you can tell, adding and you may removing the sun and rain correctly will be challenging. Unless you has a many-to-many dating in which Activity ‘s the “owning” front side, you’ll need to do extra strive to make certain brand new dating try properly up-to-date (whether you’re including the brand new labels or deleting present labels) on every Tag object in itself.
The new Symfony society has generated particular JavaScript bundles that give the new features had a need to add, revise and erase components of the newest collection. Investigate /symfony-collection bundle for modern browsers as well as the symfony-collection plan according to jQuery for the rest of browsers.
You must do one another addTag() and removeTag() procedures, if not the design commonly nonetheless fool around with setTag() even in the event by the_site was incorrect . You will then see more info on the newest removeTag() approach later on in this post.