orm: ArrayCollection->matching() not working anymore with Criteria->eq('id', $number)

Bug Report

Q A
BC Break yes
Version 2.9.6

Summary

It seems that something changed with the ->matching() method of an ArrayCollection. It persist in v2.10.1.

Current behavior

When I have an ArrayCollection I want to filter with matching and a Criteria, which has an expression like ->eq('id', $number) my script tells me something like:

“Could not resolve type of column “`id`” of class …” and so on.

How to reproduce

Let’s say you have an entity “work” with an ArrayCollection called “connectedalbums”, which stores other entities like “album”. I now want to access the album with the id “3” and would do it like this:

// $work is already fetched form the DB.

$criteria = new Criteria();
$criteria->where(Criteria::expr()->eq('id', 3));
$album = $work->getConnectedAlbums()->matching($criteria)->toArray();

if (!empty($album)) {
    $album = $album[0];
}

With this, PHP throws an Uncaught RuntimeException like mentioned above.

Expected behavior

I expect an ArrayCollection with ->matching() and the Criteria with the expression ->eq('id', $number) to give me the correct item from the ArrayCollection, whichs column id has the value, which is stored in $number. It worked like this in v2.9.5!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 27 (21 by maintainers)

Commits related to this issue

Most upvoted comments

As I wrote: “it persist in v2.10.1”. (-;

@armenio assuming this used to work in the past, you could use git bisect to find the commit that breaks your test.

@greg0ire I found! What is the next step? I don’t know the flow. please let me know what i need to know here is the result of git bisect:

armenio@MacBook-Pro doctrine-orm % git bisect bad                                                                                                    
128ebe630b14e9db45efdede6b79847ba5920bdf is the first bad commit
commit 128ebe630b14e9db45efdede6b79847ba5920bdf
Author: Laszlo_Csupity <laszlo_csupity@epam.com>
Date:   Mon Sep 13 13:55:41 2021 +0200

    Use types in collection persister

 lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Screenshot: Screen Shot 2021-11-04 at 4 54 03 PM

@armenio assuming this used to work in the past, you could use git bisect to find the commit that breaks your test.

@Tagirijus please provide a reproducer. I took some personal time to try to reproduce and fix your issue but instead I ended up showing that it’s working fine.

Fixed, nvm it just exposes that it’s working fine and this issue should be closed to me 😉 .

@greg0ire @Tagirijus isn’t this fixed?