mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-2995: Joined Inheritance Mapping and Filters #3724
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 (Feb 22, 2014).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user cappy:
Is there any reason why Inheritance Mapping IS LEFT JOINED not INNER JOINED?
When there is a filter and it's left joined it happens a record might not have parent table record. For example
Class B extends Class A.
Class A have column is_active | and filter activated with is_active = 1 condition.
Final query: LEFT JOIN parent_table s1_ ON p2_.id = s1_.id AND (s1_.is_active = '1')
Record 1 have is_active = false, so result set looks like this:
table_b | table_a
id | id is_active discriminatorColumn
1 | null null null
and occurs exception: The discriminator column ... is missing for ....
@doctrinebot commented on GitHub (Feb 22, 2014):
Comment created by @ocramius:
JTI MUST be left-joined, since not every subclass of the root of the inheritance causes inserts on all of the inheritance tables.
What is the DQL query that is causing the problem?
@doctrinebot commented on GitHub (Feb 22, 2014):
Comment created by cappy:
Hello Marco, I don't query from parent table, but from child. No sense to be LEFT JOINED.
DQL is something like that:
SELECT class1, class2 FROM Class1 class1 JOIN class1.class2 class2;
(Class2 extends Class3)
Class3 have is_active column.
And following filter:
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias) {
if (!$targetEntity->reflClass->implementsInterface('ActivateableInterface')) {
return "";
}
return $targetTableAlias . '.is_active = ' . $this->getParameter('isActive');
}
Filter condition is added in LEFT JOINED parent_table. Full example SQL:
SELECT ....
FROM class1 c1
INNER JOIN class2 c2 ON c1.c2_id = c2.id
LEFT JOIN table3 c3 ON c2.id = c3.id AND (c3.is_active = '1')
@doctrinebot commented on GitHub (Feb 26, 2014):
Comment created by @ocramius:
There are two possible solutions here:
[~cappy] can you provide a failing test case to make it easier to work on this?
@doctrinebot commented on GitHub (Feb 26, 2014):
Comment created by cappy:
Yes. Here is it sample failing test.
http://pastebin.com/xi8uUNX5 - Parent Class
http://pastebin.com/XRZLbyGX - Child Class
http://pastebin.com/HuPFb98u - Assoc Class
http://pastebin.com/hGqRk74e - TestCase
Here it should found 0 records because ot JOIN and is_active = true filter.
@doctrinebot commented on GitHub (Mar 23, 2014):
Comment created by @beberlei:
Since filters are only available on the root, i guess inner join is really necessary here.
@doctrinebot commented on GitHub (Oct 14, 2014):
Comment created by cappy:
Do you need something more? The bug is status Feedback?