Comments (6)
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.
@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.
Duplicate of doctrine/orm#5908
from collections.
Thanks @Ocramius! Didn't know there was a request on the main doctrine2 project.
from collections.
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.
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)
- Question: `Selectable` return value HOT 5
- instanceof checks in `ExpressionVisitor`
- Use splice instead of unset in ArrayCollection HOT 7
- Adding a ReadableCollection interface HOT 3
- Criteria::expr() can be null - IDE is warning us HOT 1
- Static analysis issue regarding ReadableCollection interface HOT 12
- Unable to resolve the template type TMaybeContained HOT 7
- Feature request: groupBy similar to orderBy Expression
- Feature request: add a `find` method HOT 3
- [2.1.1] Method `ArrayAccess::offsetExists()` might add `bool` as a native return type declaration in the future. HOT 3
- ReadableCollection filter method with phpstan in the context of a Collection instancied as ArrayCollection
- Psalm annotations ArrayCollection->contains() incorrect HOT 2
- Add unique() method HOT 1
- should the return type of ReadableCollection:filter() & ReadableCollection:map() not be static ? HOT 16
- Question: is there any way to reindex a collection using callable function that defines index? HOT 1
- Use looser `callable` type in place of `Closure` HOT 4
- Collection index field ignored when selecting things from a not-initialized extra lazy collection
- Enum `Order` should be correctly handled as an enum HOT 2
- Lets allow collections to be indexed by any \Stringable values
- RemoveElement return type nullable?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collections.