symfony - Doctrine Mongodb references() -
is possible doctrine mongodb createquerybuilder() add multiple references document ? here's example of want do: have 2 collections : users , movements in 1:n relation user has multiple movements , movement refers user.
to movements user, can
$user->getmovements();
i can call doctrine createquerybuilder this:
$query->createquerybuilder('movement'); $query->field('user')->references($user);
both give me expected results. if want fetch movement of 2 or 3 users in 1 query ?
is possible (which tried did not work)
$q->field('user')->references($user1); $q->field('user')->references($user2); // etc.
i stuck kind of query. ! colzak.
ok, found solution may not best 1 works.
instead of doing
$q->field('user')->references($user);
you can do
$->field('user.$id')->equals(new \mongoid($user->getid());
so if have array of user, can like
$userids = array(); foreach ($users $user) { $userids[] = new \mongdoid($user->getid()); }
and query:
$q->field('user.$id')->in($userids);
hope it'll !
Comments
Post a Comment