fix linked where filters
This commit is contained in:
@@ -1358,16 +1358,22 @@ class ItemGeneralConverter implements ItemConverter
|
|||||||
$nearKey = $defs->getMidKey();
|
$nearKey = $defs->getMidKey();
|
||||||
$middleEntityType = ucfirst($defs->getRelationshipName());
|
$middleEntityType = ucfirst($defs->getRelationshipName());
|
||||||
|
|
||||||
|
$conditions = [
|
||||||
|
"$alias.$nearKey:" => Attribute::ID,
|
||||||
|
"$alias.deleted" => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($defs->getConditions() as $k => $v) {
|
||||||
|
$conditions["$alias.$k"] = $v;
|
||||||
|
}
|
||||||
|
|
||||||
// The foreign table is not joined as it would perform much slower.
|
// The foreign table is not joined as it would perform much slower.
|
||||||
// Trade off is that if a foreign record is deleted but the middle table
|
// Trade off is that if a foreign record is deleted but the middle table
|
||||||
// is not yet deleted, it will give a non-actual result.
|
// is not yet deleted, it will give a non-actual result.
|
||||||
$subQuery = QueryBuilder::create()
|
$subQuery = QueryBuilder::create()
|
||||||
->select(Attribute::ID)
|
->select(Attribute::ID)
|
||||||
->from($this->entityType)
|
->from($this->entityType)
|
||||||
->leftJoin($middleEntityType, $alias, [
|
->leftJoin($middleEntityType, $alias, $conditions)
|
||||||
"$alias.$nearKey:" => Attribute::ID,
|
|
||||||
"$alias.deleted" => false,
|
|
||||||
])
|
|
||||||
->where(["$alias.$key" => null])
|
->where(["$alias.$key" => null])
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
@@ -1410,16 +1416,22 @@ class ItemGeneralConverter implements ItemConverter
|
|||||||
$nearKey = $defs->getMidKey();
|
$nearKey = $defs->getMidKey();
|
||||||
$middleEntityType = ucfirst($defs->getRelationshipName());
|
$middleEntityType = ucfirst($defs->getRelationshipName());
|
||||||
|
|
||||||
|
$conditions = [
|
||||||
|
"$alias.$nearKey:" => Attribute::ID,
|
||||||
|
"$alias.deleted" => false,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($defs->getConditions() as $k => $v) {
|
||||||
|
$conditions["$alias.$k"] = $v;
|
||||||
|
}
|
||||||
|
|
||||||
// The foreign table is not joined as it would perform much slower.
|
// The foreign table is not joined as it would perform much slower.
|
||||||
// Trade off is that if a foreign record is deleted but the middle table
|
// Trade off is that if a foreign record is deleted but the middle table
|
||||||
// is not yet deleted, it will give a non-actual result.
|
// is not yet deleted, it will give a non-actual result.
|
||||||
$subQuery = QueryBuilder::create()
|
$subQuery = QueryBuilder::create()
|
||||||
->select(Attribute::ID)
|
->select(Attribute::ID)
|
||||||
->from($this->entityType)
|
->from($this->entityType)
|
||||||
->leftJoin($middleEntityType, $alias, [
|
->leftJoin($middleEntityType, $alias, $conditions)
|
||||||
"$alias.$nearKey:" => Attribute::ID,
|
|
||||||
"$alias.deleted" => false,
|
|
||||||
])
|
|
||||||
->where(["$alias.$key!=" => null])
|
->where(["$alias.$key!=" => null])
|
||||||
->build();
|
->build();
|
||||||
|
|
||||||
@@ -1476,7 +1488,6 @@ class ItemGeneralConverter implements ItemConverter
|
|||||||
|
|
||||||
if ($relationType == Entity::MANY_MANY) {
|
if ($relationType == Entity::MANY_MANY) {
|
||||||
$key = $defs->getForeignMidKey();
|
$key = $defs->getForeignMidKey();
|
||||||
$nearKey = $defs->getMidKey();
|
|
||||||
|
|
||||||
// IN-sub-query performs faster than EXISTS on MariaDB when multiple IDs.
|
// IN-sub-query performs faster than EXISTS on MariaDB when multiple IDs.
|
||||||
// Left-join performs faster than inner-join.
|
// Left-join performs faster than inner-join.
|
||||||
@@ -1489,12 +1500,6 @@ class ItemGeneralConverter implements ItemConverter
|
|||||||
->from($this->entityType)
|
->from($this->entityType)
|
||||||
->leftJoin(
|
->leftJoin(
|
||||||
Join::create($link, $alias)
|
Join::create($link, $alias)
|
||||||
->withConditions(
|
|
||||||
Cond::equal(
|
|
||||||
Cond::column("$alias.$nearKey"),
|
|
||||||
Cond::column(Attribute::ID)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->withOnlyMiddle()
|
->withOnlyMiddle()
|
||||||
)
|
)
|
||||||
->where(["$alias.$key" => $value])
|
->where(["$alias.$key" => $value])
|
||||||
|
|||||||
@@ -372,9 +372,8 @@ class ConverterTest extends TestCase
|
|||||||
[
|
[
|
||||||
'test',
|
'test',
|
||||||
$alias,
|
$alias,
|
||||||
[$alias . '.localId=:' => 'id'],
|
null,
|
||||||
[
|
[
|
||||||
'noLeftAlias' => true,
|
|
||||||
'onlyMiddle' => true,
|
'onlyMiddle' => true,
|
||||||
'type' => JoinType::left,
|
'type' => JoinType::left,
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user