V
V
VesX2014-06-23 15:16:08
OOP
VesX, 2014-06-23 15:16:08

Why is Symfony2 Form calling remove* along with add* ?

The entity has a posts property.
If you make a setter

setPosts($posts)
{
    //...
}

then everything is fine, everything is as it should be. The field is assigned the necessary posts
And if instead of set it will be add
addPosts($posts)
{
    //...
}

Something incomprehensible is happening. The form will require that in addition to addPosts($posts) there must also be removePosts($posts) . And will call it before/after addPosts($posts)
There are both methods in the class. Both add* and remove*.
Question: How can I prevent remove* from being called along with add* ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svscorp, 2014-06-26
@svscorp

When we talk about add and remove, we mean working with the ManyToMany relation, for example, i.e. with ArrayCollections.
Those. if your entity has a post s property that is a ManyToMany or OneToMany to a Post entity, then Symfony will look for addPost(Post $post) and removePost(Post $post).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question