DDC-2051: after filtering an association by using ->matching(Criteria) original association changes #2584

Closed
opened 2026-01-22 13:57:35 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Oct 2, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user iamkoby:

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.

Originally created by @doctrinebot on GitHub (Oct 2, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user iamkoby: 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.
admin added the Bug label 2026-01-22 13:57:35 +01:00
admin closed this issue 2026-01-22 13:57:35 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 2, 2012):

Comment created by iamkoby:

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.

@doctrinebot commented on GitHub (Oct 2, 2012): Comment created by iamkoby: 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.
Author
Owner

@doctrinebot commented on GitHub (Oct 6, 2012):

Comment created by @beberlei:

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

@doctrinebot commented on GitHub (Oct 6, 2012): Comment created by @beberlei: Can you add a code example? I don't understand what you mean.
Author
Owner

@doctrinebot commented on GitHub (Oct 7, 2012):

Comment created by iamkoby:

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.

@doctrinebot commented on GitHub (Oct 7, 2012): Comment created by iamkoby: 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.
Author
Owner

@doctrinebot commented on GitHub (Oct 15, 2012):

Comment created by iamkoby:

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

sorry

@doctrinebot commented on GitHub (Oct 15, 2012): Comment created by iamkoby: this was due to inconsistent association type in both owner and target (target had one-to-one while owner had one-to-many) sorry
Author
Owner

@doctrinebot commented on GitHub (Oct 15, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Oct 15, 2012): Issue was closed with resolution "Invalid"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2584