Using Doctrine 2, if I retrieve an entity by primary key and make a change to a field without flushing to the database, a subsequent criteria match will query the database for the association and incorrectly return the record with in memory changes. This record should be excluded, however because it hasn't been flushed the query still retrieves it.
Given this function:
public function getActiveUsers()
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('active', true));
return $this->users->matching($criteria);
}
Running the following will output "true true"
foreach($organisation->getActiveUsers() as $user)
echo ($user->isActive() ? 'true' : 'false');
However, marking one of those users as inactive and then running the same criteria match will output "false true" (should only output a single "true" as the first record should be excluded)
User::get(1)->setActive(false);
foreach($organisation->getActiveUsers() as $user)
echo ($user->isActive() ? 'true' : 'false');
This bug is forcing me to perform a flush before every criteria query which is extremely draining on performance. If anyone can shed some light on this it would be appreciated