Skip to content

Commit

Permalink
fix ambigious column on many to many with select load
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 28, 2020
1 parent 6611265 commit 5007986
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Concerns\BuildsQueries;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Builder as QueryBuilder;
use Illuminate\Pagination\Paginator;
Expand Down Expand Up @@ -1143,7 +1144,11 @@ protected function parseWithRelations(array $relations)
protected function createSelectWithConstraint($name)
{
return [explode(':', $name)[0], static function ($query) use ($name) {
$query->select(explode(',', explode(':', $name)[1]));
$query->select(array_map(static function ($column) use ($query) {
return $query instanceof BelongsToMany
? $query->getRelated()->getTable().'.'.$column
: $column;
}, explode(',', explode(':', $name)[1])));
}];
}

Expand Down

0 comments on commit 5007986

Please sign in to comment.