Skip to content

Commit b019174

Browse files
committed
DB: Updated entity scope to use models dynamic table
This was hardcoded since the table was always the same, but in some cases Laravel will auto-alias the table name (for example, when in sub-queries) which will break MySQL 5.7 when the scope attempts to use the table name instead of the alias. Needs testing coverage. For #5877
1 parent 5bf2d80 commit b019174

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

app/Entities/Models/EntityScope.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ class EntityScope implements Scope
1515
public function apply(Builder $builder, Model $model): void
1616
{
1717
$builder = $builder->where('type', '=', $model->getMorphClass());
18+
$table = $model->getTable();
1819
if ($model instanceof Page) {
19-
$builder->leftJoin('entity_page_data', 'entity_page_data.page_id', '=', 'entities.id');
20+
$builder->leftJoin('entity_page_data', 'entity_page_data.page_id', '=', "{$table}.id");
2021
} else {
21-
$builder->leftJoin('entity_container_data', function (JoinClause $join) use ($model) {
22-
$join->on('entity_container_data.entity_id', '=', 'entities.id')
22+
$builder->leftJoin('entity_container_data', function (JoinClause $join) use ($model, $table) {
23+
$join->on('entity_container_data.entity_id', '=', "{$table}.id")
2324
->where('entity_container_data.entity_type', '=', $model->getMorphClass());
2425
});
2526
}

0 commit comments

Comments
 (0)