mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-623: Allow DiscriminatorColumn nullable=false #764
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 @doctrinebot on GitHub (Jun 2, 2010).
Originally assigned to: @guilhermeblanco on GitHub.
Jira issue originally created by user dennis.verspuij:
Currently it is not possible to specify nullable=false for a DiscriminatorColumn mapping.
I'd like this to force persisted objects to be instances of one of the subclasses, thus disallowing instances of the base class. I can't use MappedSuperClass for this because I want single table inheritance so I can query the base class and expect only instances of subclasses as results.
For example take mapping:
/****
@Entity
@Table (name="person")
@InheritanceType ("SINGLE_TABLE")
@DiscriminatorColumn (name="kind", type="integer", length=1)
@DiscriminatorMap ({ 0="author", 1="reader" })
*/
class Person
{
...
Currently a DQL query:
SELECT * FROM Person
would execute SQL like:
SELECT q0_.id AS id0, ... FROM person q0_ WHERE q0_.kind IN ('', '0', '1')
Allowing nullable=FALSE would make the database column not-nullable. I would expect this anyway because the base class itself should be in the DiscriminatorMap as well, but I didn't provide it. Furthermore the IN(...) clause should not contain the empty string value (which is useless anyway in my example because the discriminator is of type integer). At last the IN(...) clause is redundant here as well and may slow down execution.
I'd be welcome to write a test case. Greetings.