Skip to content

Commit 536432a

Browse files
committed
Column disambiguation in closure table queries
1 parent 35356b4 commit 536432a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Models/Entity.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,12 @@ private function buildAncestorsQuery(Builder $builder, $id, $withSelf)
430430
return $builder
431431
->join(
432432
$this->closure->getTable(),
433-
$this->closure->getAncestorColumn(),
433+
$this->closure->getQualifiedAncestorColumn(),
434434
'=',
435435
$this->getQualifiedKeyName()
436436
)
437-
->where($this->closure->getDescendantColumn(), '=', $id)
438-
->where($this->closure->getDepthColumn(), $depthOperator, 0);
437+
->where($this->closure->getQualifiedDescendantColumn(), '=', $id)
438+
->where($this->closure->getQualifiedDepthColumn(), $depthOperator, 0);
439439
}
440440

441441
/**
@@ -563,12 +563,12 @@ private function buildDescendantsQuery(Builder $builder, $id, $withSelf)
563563
return $builder
564564
->join(
565565
$this->closure->getTable(),
566-
$this->closure->getDescendantColumn(),
566+
$this->closure->getQualifiedDescendantColumn(),
567567
'=',
568568
$this->getQualifiedKeyName()
569569
)
570-
->where($this->closure->getAncestorColumn(), '=', $id)
571-
->where($this->closure->getDepthColumn(), $depthOperator, 0);
570+
->where($this->closure->getQualifiedAncestorColumn(), '=', $id)
571+
->where($this->closure->getQualifiedDepthColumn(), $depthOperator, 0);
572572
}
573573

574574
/**

tests/migrations/2014_01_18_162506_create_entities_table.php

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public function up()
2121
$table->integer('position', false, true);
2222
$table->softDeletes();
2323

24+
// Ensures there are no ambiguous column names in queries involving the closure table
25+
$table->integer('ancestor')->nullable();
26+
$table->integer('descendant')->nullable();
27+
$table->integer('depth')->nullable();
28+
2429
$table->foreign('parent_id')->references('id')->on('entities')->onDelete('set null');
2530

2631
$table->engine = 'InnoDB';

0 commit comments

Comments
 (0)