Im working with Laravel 4 and mongodb 2.0.4 module I have User and Role class and Im trying to use belongsToMany relation with attach, detach and sync methods
User class
public function roles()
{
return $this->belongsToMany('Role', null, 'user_ids', 'role_ids');
}
Role class
public function users()
{
return $this->belongsToMany('User', null, 'role_ids', 'user_ids'
}
When I run attach method
$user = User::find($id);
$user->roles()->attach(array($role_id));
mongodb generate one of the query wrong (or not?)
user.update({"_id":{"$id":"54f8d7802228d5e42b000036"}},{"$addToSet":{"role_ds":{"$each":["54f8d7b02228d5e42b000037"]}}},{"multiple":true})
role.update({"_id":["54f8d7b02228d5e42b000037"]},{"$addToSet":{"user_ids":{"$each":["54f8d7802228d5e42b000036"]}}},{"multiple":true})
user collection is updated but role collection stay intact. It should generate query like this?
role.update({"_id":{"$id":"54f8d7b02228d5e42b000037"}},{"$addToSet":{"user_ids":{"$each":["54f8d7802228d5e42b000036"]}}},{"multiple":true})
This problem is present with both attach and detach methods. Only sync runs correctly. But only if there is one element. If you run sync on multiple elements one of the collections stays always intact because of wrong query.
Am I missing something or there is really a problem with this relation? Any help would be great. Thank you