Skip to content

Commit 5007986

Browse files
committed
fix ambigious column on many to many with select load
1 parent 6611265 commit 5007986

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Diff for: src/Illuminate/Database/Eloquent/Builder.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Exception;
88
use Illuminate\Contracts\Support\Arrayable;
99
use Illuminate\Database\Concerns\BuildsQueries;
10+
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
1011
use Illuminate\Database\Eloquent\Relations\Relation;
1112
use Illuminate\Database\Query\Builder as QueryBuilder;
1213
use Illuminate\Pagination\Paginator;
@@ -1143,7 +1144,11 @@ protected function parseWithRelations(array $relations)
11431144
protected function createSelectWithConstraint($name)
11441145
{
11451146
return [explode(':', $name)[0], static function ($query) use ($name) {
1146-
$query->select(explode(',', explode(':', $name)[1]));
1147+
$query->select(array_map(static function ($column) use ($query) {
1148+
return $query instanceof BelongsToMany
1149+
? $query->getRelated()->getTable().'.'.$column
1150+
: $column;
1151+
}, explode(',', explode(':', $name)[1])));
11471152
}];
11481153
}
11491154

0 commit comments

Comments
 (0)