Skip to content

Commit 006ba38

Browse files
vdlp-mwMenzo Wijmenga
and
Menzo Wijmenga
authored
Use qualified column names in pivot query (#36720)
Co-authored-by: Menzo Wijmenga <menzo@vdlp.nl>
1 parent efba08c commit 006ba38

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ public function detach($ids = null, $touch = true)
429429
return 0;
430430
}
431431

432-
$query->whereIn($this->relatedPivotKey, (array) $ids);
432+
$query->whereIn($this->getQualifiedRelatedPivotKeyName(), (array) $ids);
433433
}
434434

435435
// Once we have all of the conditions set on the statement, we are ready
@@ -544,7 +544,7 @@ public function newPivotQuery()
544544
$query->whereIn(...$arguments);
545545
}
546546

547-
return $query->where($this->foreignPivotKey, $this->parent->{$this->parentKey});
547+
return $query->where($this->getQualifiedForeignPivotKeyName(), $this->parent->{$this->parentKey});
548548
}
549549

550550
/**

tests/Database/DatabaseEloquentMorphToManyTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ public function testDetachRemovesPivotTableRecord()
4747
$relation = $this->getMockBuilder(MorphToMany::class)->setMethods(['touchIfTouching'])->setConstructorArgs($this->getRelationArguments())->getMock();
4848
$query = m::mock(stdClass::class);
4949
$query->shouldReceive('from')->once()->with('taggables')->andReturn($query);
50-
$query->shouldReceive('where')->once()->with('taggable_id', 1)->andReturn($query);
50+
$query->shouldReceive('where')->once()->with('taggables.taggable_id', 1)->andReturn($query);
5151
$query->shouldReceive('where')->once()->with('taggable_type', get_class($relation->getParent()))->andReturn($query);
52-
$query->shouldReceive('whereIn')->once()->with('tag_id', [1, 2, 3]);
52+
$query->shouldReceive('whereIn')->once()->with('taggables.tag_id', [1, 2, 3]);
5353
$query->shouldReceive('delete')->once()->andReturn(true);
5454
$relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock(stdClass::class));
5555
$mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query);
@@ -63,7 +63,7 @@ public function testDetachMethodClearsAllPivotRecordsWhenNoIDsAreGiven()
6363
$relation = $this->getMockBuilder(MorphToMany::class)->setMethods(['touchIfTouching'])->setConstructorArgs($this->getRelationArguments())->getMock();
6464
$query = m::mock(stdClass::class);
6565
$query->shouldReceive('from')->once()->with('taggables')->andReturn($query);
66-
$query->shouldReceive('where')->once()->with('taggable_id', 1)->andReturn($query);
66+
$query->shouldReceive('where')->once()->with('taggables.taggable_id', 1)->andReturn($query);
6767
$query->shouldReceive('where')->once()->with('taggable_type', get_class($relation->getParent()))->andReturn($query);
6868
$query->shouldReceive('whereIn')->never();
6969
$query->shouldReceive('delete')->once()->andReturn(true);

0 commit comments

Comments
 (0)