Hi guys,
Hoping someone can help with this issue on criteria matching. I have a
parent -> child relationship and need to filter to only return "active"
children.
public function getUsers()
{
return $this->users;
}
public function getActiveUsers()
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('active', true));
/** @noinspection PhpUndefinedMethodInspection */
return $this->getUsers()->matching($criteria);
}
The above code works fine as long as there are no uncommitted changes to
the database in memory. However, if I have retrieved a user from the
database, marked it as inactive in memory and then call the
'getActiveUsers' function, it is still returning me the inactive user.
I believe that if I have previously loaded the 'getUsers' collection from
the database, when the criteria filters it will be done in memory and
therefore removes the inactive user from the collection, but if I haven't
previously loaded the users collection, it only queries the database and
hence doesn't filter it out.
Is this an issue with how I am using the criteria? Or an underlying issue
with how it is performing the filter? At the moment the only solution I can
see is to flush changes to the database before I use the criteria filter.
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.