Skip to content

NOW MANAGED ON CODEBERG

DB: Updated entity scope to use models dynamic table

Dan Brown4eb4407ef76c
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());
});
}