Proposal: Ability to select specific type when using inheritance #7070

Open
opened 2026-01-22 15:44:04 +01:00 by admin · 4 comments
Owner

Originally created by @zim32 on GitHub (Nov 11, 2022).

Feature Request

Q A
New Feature yes
RFC no
BC Break no

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:

WHERE m INSTANCE OF A // will select A, B and C.
WHERE m INSTANCE OF B // will select B and C. 

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):

// to select only A instances
SELECT a FROM '.A::class.' a WHERE a NOT INSTANCE OF B
// to select only B instances
SELECT b FROM '.B::class.' b WHERE b NOT INSTANCE OF C
// and so on

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.

Originally created by @zim32 on GitHub (Nov 11, 2022). ### Feature Request <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ------ | New Feature | yes | RFC | no | BC Break | no #### 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: ``` WHERE m INSTANCE OF A // will select A, B and C. WHERE m INSTANCE OF B // will select B and C. ``` **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): ``` // to select only A instances SELECT a FROM '.A::class.' a WHERE a NOT INSTANCE OF B // to select only B instances SELECT b FROM '.B::class.' b WHERE b NOT INSTANCE OF C // and so on ``` **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.
admin added the New Feature label 2026-01-22 15:44:04 +01:00
Author
Owner

@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 🤔

@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 🤔
Author
Owner

@zim32 commented on GitHub (Nov 12, 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 thinking

MEMBER OF is about collections. I am talking about selecting entities of specific type.

@zim32 commented on GitHub (Nov 12, 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 thinking MEMBER OF is about collections. I am talking about selecting entities of specific type.
Author
Owner

@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): I made a mistake in my proposed keyword. Not TYPE OF but OF TYPE. I will change proposal text
Author
Owner

@zim32 commented on GitHub (Nov 12, 2022):

Add NOT examples to proposal

@zim32 commented on GitHub (Nov 12, 2022): Add NOT examples to proposal
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7070