-
Notifications
You must be signed in to change notification settings - Fork 236
Support for join conditions (using 'WITH') #820
base: master
Are you sure you want to change the base?
Conversation
// for the last dql part join using WITH, if expression is given for column | ||
if (count($parts) === 1 && array_key_exists($columnTableName, $this->joins) && null !== $withExpr) { | ||
$with = str_replace($currentPart . '.', $currentAlias . '.', $withExpr); | ||
$this->addJoin($columnTableName, $currentAlias, $this->accessor->getValue($column, 'joinType'), $with); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a "complex" join like table1.table2.table3.field
, maybe we want to set a different join condition on each join.
How do you handle it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's possible by adding a column of each joined table to the column builder and defining the respective join condition.
$this->columnBuilder
->add('table1.table2.id', Column\Column::class, array(
'visible' => false,
'join_conditions' => 'table2.enabled = 1'
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you tried it?
Is the table2.enabled = 1
not applied on the table1.table2
join?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, its applied on the table1.table2
join. If you then add a join to table3
you have different join conditions on each join. Or am I misunderstanding the question?
$this->columnBuilder
->add('table1.id', Column\Column::class, array()) // see comment below
->add('table1.table2.id', Column\Column::class, array(
'join_conditions' => 'table2.enabled = 1'
))
->add('table1.table2.table3.id', Column\Column::class, array()) // see comment below
->add('table1.table2.table3.field', Column\Column::class, array(
'join_conditions' => 'table3.otherField = 0'
));
During my tests I noticed that the joins only worked if the ids of the joined tables were explicitly included as columns in the datatable. Otherwise doctrine will throw an exception Cannot select distinct identifiers from query with LIMIT and ORDER BY on a column from a fetch joined to-many association. Use output walkers.
But this also happens without the changes I made in this PR and the usage of join_conditions
.
Thanks for providing a PR! Unfortunately, this library hasn't got many unit tests (yet). Are you willing to contribute by adding a tests for this new feature? |
As mentioned in #700 this PR adds support for join conditions.