From 4eb4407ef76cac144e4149e7b2ba461b168d3a3b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 10 Nov 2025 19:46:49 +0000 Subject: [PATCH] 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 --- app/Entities/Models/EntityScope.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Entities/Models/EntityScope.php b/app/Entities/Models/EntityScope.php index deb10c5ec..c77b75a16 100644 --- a/app/Entities/Models/EntityScope.php +++ b/app/Entities/Models/EntityScope.php @@ -15,11 +15,12 @@ class EntityScope implements Scope public function apply(Builder $builder, Model $model): void { $builder = $builder->where('type', '=', $model->getMorphClass()); + $table = $model->getTable(); if ($model instanceof Page) { - $builder->leftJoin('entity_page_data', 'entity_page_data.page_id', '=', 'entities.id'); + $builder->leftJoin('entity_page_data', 'entity_page_data.page_id', '=', "{$table}.id"); } else { - $builder->leftJoin('entity_container_data', function (JoinClause $join) use ($model) { - $join->on('entity_container_data.entity_id', '=', 'entities.id') + $builder->leftJoin('entity_container_data', function (JoinClause $join) use ($model, $table) { + $join->on('entity_container_data.entity_id', '=', "{$table}.id") ->where('entity_container_data.entity_type', '=', $model->getMorphClass()); }); }