mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Proposal: Ability to select specific type when using inheritance #7070
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @zim32 on GitHub (Nov 11, 2022).
Feature Request
Summary
Let's imagine we have entity C which inhertits from B which inherits from A:
C --> B --> A
When dealing with inheritance we have INSTANCE OF operator:
INSTANCE OF always works with whole inherticance chain.
If I want to select specific type, I always need to specify NOT INSTANCE OF (upper bound class):
Somtines we just don't know upper bound class beforehand.
Proposal
I propose to add [NOT] OF TYPE operator which will select only specific type:
SELECT a FROM '.A::class.' a WHERE a OF TYPE A // will select only A instances
SELECT b FROM '.B::class.' b WHERE b OF TYPE B // will select only B instances
SELECT a FROM '.A::class.' a WHERE a NOT OF TYPE C // will select A AND B instances
SELECT a FROM '.A::class.' a WHERE a NOT OF TYPE A // will select B AND C instances
I already have a working example in my local branch, so if this proposal will be accepted, I can create a pull request.
@michaljusiega commented on GitHub (Nov 11, 2022):
I've never used the MEMBER OF keyword that currently exists in implementation.
Have you ever tried with this solution?
... or I am totally wrong 🤔
@zim32 commented on GitHub (Nov 12, 2022):
MEMBER OF is about collections. I am talking about selecting entities of specific type.
@zim32 commented on GitHub (Nov 12, 2022):
I made a mistake in my proposed keyword. Not TYPE OF but OF TYPE. I will change proposal text
@zim32 commented on GitHub (Nov 12, 2022):
Add NOT examples to proposal