Good day everyone! I have a question about collection persistence in Symfony and Doctrine
The short version
I can add an item to collection (persist) via form, but can not remove (remove).
The logics
I need a possibility to add users to business trips. Each added user must have text description (like a objective for business trip).
In fact, i have 3 entities:
- BusinessTrip
- BusinessTripUser (stores linked User id, BusinessTrip id and text field "description")
- User (vendor bundle entity)
The problem
As i already said above - i cant remove BusinessTripUser from collection $users in BusinessTrip. I mentioned that if i remove unidirectional relation between BusinessTripUser and User - everything work fine. It looks like this relation prevents orphanRemoval mechanism delete the orphaned BusinessTripUser enity.
Relations between entities
class BusinessTrip
{
/**
* @ORM\OneToMany(targetEntity="OQ\BusinessTripBundle\Entity\BusinessTripUser", mappedBy="businessTrip", cascade={"persist","remove"}, orphanRemoval=true)
*/
protected $users;
}
class BusinessTripUser
/**
* @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
protected $user;
/**
* @ORM\ManyToOne(targetEntity="OQ\BusinessTripBundle\Entity\BusinessTrip", inversedBy="users")
* @ORM\JoinColumn(name="business_trip_id", referencedColumnName="id", nullable=false)
*/
protected $businessTrip;
}
Symfony v2.7.3, Doctrine v2.5.1