Reputation: 642
I have entity User
which has many to many relation to roles. I've tried to implement Optimistic lock, everything works fine, just when I changed roles, it doesn't change the version (User entity version), is this proper behaviour?
class User {
/**
* User's roles.
*
* @ORM\ManyToMany(targetEntity="Role")
*/
private $roles;
...
Upvotes: 2
Views: 1483
Reputation: 21817
Doctrine 2's locking mechanisms don't take associations into account. They only protect against changes to the entities themselves. IMHO this is expected, because it has no way to know which associations to include and which to ignore. This isn't something you'd want to happen blindly on all associations.
Theoretically Doctrine 2 could achieve this by adding an option to the association mappings, but at this moment that simply isn't supported.
So you have 2 options:
Upvotes: 1
Reputation: 422
I didn't try, but I think this is proper bahaviour (because flush don't modify User entity) and there is no reason to lock User entity - it's not changed.
Upvotes: 0