Skip to content

Commit

Permalink
Use qualified column names in pivot query (#36720)
Browse files Browse the repository at this point in the history
Co-authored-by: Menzo Wijmenga <menzo@vdlp.nl>
  • Loading branch information
vdlp-mw and Menzo Wijmenga authored Mar 26, 2021
1 parent efba08c commit 006ba38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function detach($ids = null, $touch = true)
return 0;
}

$query->whereIn($this->relatedPivotKey, (array) $ids);
$query->whereIn($this->getQualifiedRelatedPivotKeyName(), (array) $ids);
}

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

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

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Database/DatabaseEloquentMorphToManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public function testDetachRemovesPivotTableRecord()
$relation = $this->getMockBuilder(MorphToMany::class)->setMethods(['touchIfTouching'])->setConstructorArgs($this->getRelationArguments())->getMock();
$query = m::mock(stdClass::class);
$query->shouldReceive('from')->once()->with('taggables')->andReturn($query);
$query->shouldReceive('where')->once()->with('taggable_id', 1)->andReturn($query);
$query->shouldReceive('where')->once()->with('taggables.taggable_id', 1)->andReturn($query);
$query->shouldReceive('where')->once()->with('taggable_type', get_class($relation->getParent()))->andReturn($query);
$query->shouldReceive('whereIn')->once()->with('tag_id', [1, 2, 3]);
$query->shouldReceive('whereIn')->once()->with('taggables.tag_id', [1, 2, 3]);
$query->shouldReceive('delete')->once()->andReturn(true);
$relation->getQuery()->shouldReceive('getQuery')->andReturn($mockQueryBuilder = m::mock(stdClass::class));
$mockQueryBuilder->shouldReceive('newQuery')->once()->andReturn($query);
Expand All @@ -63,7 +63,7 @@ public function testDetachMethodClearsAllPivotRecordsWhenNoIDsAreGiven()
$relation = $this->getMockBuilder(MorphToMany::class)->setMethods(['touchIfTouching'])->setConstructorArgs($this->getRelationArguments())->getMock();
$query = m::mock(stdClass::class);
$query->shouldReceive('from')->once()->with('taggables')->andReturn($query);
$query->shouldReceive('where')->once()->with('taggable_id', 1)->andReturn($query);
$query->shouldReceive('where')->once()->with('taggables.taggable_id', 1)->andReturn($query);
$query->shouldReceive('where')->once()->with('taggable_type', get_class($relation->getParent()))->andReturn($query);
$query->shouldReceive('whereIn')->never();
$query->shouldReceive('delete')->once()->andReturn(true);
Expand Down

0 comments on commit 006ba38

Please sign in to comment.