GithubHelp home page GithubHelp logo

Comments (6)

7ochem avatar 7ochem commented on August 15, 2024 3

I wanted to filter a collection by a specific type and ran into the same issue:

$object->getItems()->matching(
    Criteria::create()->where(
        Criteria::expr()->instanceOf(Some::class)
    )
);

But instanceOf() obviously does not exist. The "items" here is a collection of subtypes which all extend some base class.

If this is still a thing, then I could take a shot at this and try to add it to doctrine/collections and doctrine/orm

from collections.

trickeyone avatar trickeyone commented on August 15, 2024 2

@7ochem It looks like my PR (#249) was accepted and added to 1.6.8, which restored only strict-checking for scalar values. This re-enabled my original work-around. That said, I think having an equivalent of INSTANCE OF for collections would be extremely beneficial.

from collections.

Ocramius avatar Ocramius commented on August 15, 2024

Duplicate of doctrine/orm#5908

from collections.

trickeyone avatar trickeyone commented on August 15, 2024

Thanks @Ocramius! Didn't know there was a request on the main doctrine2 project.

from collections.

trickeyone avatar trickeyone commented on August 15, 2024

As a note, I've found that if I use:

$type1 = new Type\Type1();
$type2 = new Type\Type2();
Criteria::expr()->andWhere(
  'field',
  Criteria::expr()->in([$type1, $type2])
);

Where Type/Type1 and Type/Type2 are discriminators with IDs, the desired outcome can be achieved.

from collections.

trickeyone avatar trickeyone commented on August 15, 2024

Followup on my previous comment. My solution that did work for 1.4 doesn't work with 1.5 because the Comparison::IN comparator now does a strict in_array

from collections.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.