[DDC-2051] after filtering an association by using ->matching(Criteria) original association changes Created: 02/Oct/12  Updated: 15/Oct/12  Resolved: 15/Oct/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.3
Fix Version/s: 2.4
Security Level: All

Type: Bug Priority: Major
Reporter: Koby Soto Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: None


 Description   

after filtering an association with a criteria it changes so it's not a normal collection and you can't re-filter it.

even after hydrating it you can't filter it.



 Comments   
Comment by Koby Soto [ 02/Oct/12 ]

The filtering only works once and only if the database hasn't been queried!

This is a major bug because i would like to filter big collections more than once per request.

Comment by Benjamin Eberlei [ 06/Oct/12 ]

Can you add a code example? I don't understand what you mean.

Comment by Koby Soto [ 07/Oct/12 ]

sure: here's just an example (written right now to demonstrate, not taken from real project, so no criticize pls):

Let's say we have two functions:

1. function getExpensiveBooks($limit)

{ $books = $this->getBooks(); //proxy, haven't queried yet. $criteria = Criteria::create()->where(Criteria::expr()->gt('price', '10'))->setMaxResults($limit); return $books->matching($criteria); }

2. function getCheapBooks($limit)

{ $books = $this->getBooks(); //proxy, haven't queried yet. $criteria = Criteria::create()->where(Criteria::expr()->lt('price', '4'))->setMaxResults($limit); return $books->matching($criteria); }

now, let's say that in the controller i've called:
$expensiveBooks = $author->getExpensiveBooks(3); //will work fine, and the query will be according the criteria.
//but going on and doing this:
$cheapBooks = $author->getCheapBooks(3); //will not work: matching is undefined function.

It appears that doing matching only works on the first time on a certain association.

Comment by Koby Soto [ 15/Oct/12 ]

this was due to inconsistent association type in both owner and target (target had one-to-one while owner had one-to-many)

sorry

Generated at Thu Aug 21 12:16:25 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.