|
14 | 14 | use Illuminate\Database\Eloquent\Relations\MorphToMany; |
15 | 15 |
|
16 | 16 | /** |
17 | | - * @method getModel |
| 17 | + * @method \Illuminate\Database\Eloquent\Model getModel() |
| 18 | + * @method string getTable() |
| 19 | + * @method string getForeignPivotKeyName() |
| 20 | + * @method string getRelatedPivotKeyName() |
| 21 | + * @method bool isOneOfMany() |
| 22 | + * @method \Illuminate\Database\Eloquent\Builder|void getOneOfManySubQuery() |
| 23 | + * @method \Illuminate\Database\Eloquent\Builder getQuery() |
| 24 | + * @method \Illuminate\Database\Eloquent\Model getThroughParent() |
| 25 | + * @method string getForeignKeyName() |
| 26 | + * @method string getMorphType() |
| 27 | + * @method string getMorphClass() |
| 28 | + * @method string getFirstKeyName() |
| 29 | + * @method string getQualifiedLocalKeyName() |
| 30 | + * @method string getExistenceCompareKey() |
18 | 31 | * @mixin \Illuminate\Database\Eloquent\Relations\Relation |
| 32 | + * @mixin \Illuminate\Database\Eloquent\Relations\HasOneOrMany |
| 33 | + * @mixin \Illuminate\Database\Eloquent\Relations\BelongsToMany |
| 34 | + * @property \Illuminate\Database\Eloquent\Builder $query |
| 35 | + * @property \Illuminate\Database\Eloquent\Model $parent |
| 36 | + * @property \Illuminate\Database\Eloquent\Model $throughParent |
| 37 | + * @property string $foreignKey |
| 38 | + * @property string $parentKey |
| 39 | + * @property string $ownerKey |
| 40 | + * @property string $localKey |
| 41 | + * @property string $secondKey |
| 42 | + * @property string $secondLocalKey |
| 43 | + * @property \Illuminate\Database\Eloquent\Model $farParent |
19 | 44 | */ |
20 | 45 | class RelationshipsExtraMethods |
21 | 46 | { |
@@ -226,6 +251,15 @@ protected function performJoinForEloquentPowerJoinsForHasMany() |
226 | 251 | return function ($builder, $joinType, $callback = null, $alias = null, bool $disableExtraConditions = false) { |
227 | 252 | $joinedTable = $alias ?: $this->query->getModel()->getTable(); |
228 | 253 | $parentTable = StaticCache::getTableOrAliasForModel($this->parent); |
| 254 | + $isOneOfMany = method_exists($this, 'isOneOfMany') ? $this->isOneOfMany() : false; |
| 255 | + |
| 256 | + if ($isOneOfMany) { |
| 257 | + foreach ($this->getOneOfManySubQuery()->getQuery()->columns as $column) { |
| 258 | + $builder->addSelect($column); |
| 259 | + } |
| 260 | + |
| 261 | + $builder->take(1); |
| 262 | + } |
229 | 263 |
|
230 | 264 | $builder->{$joinType}($this->query->getModel()->getTable(), function ($join) use ($callback, $joinedTable, $parentTable, $alias, $disableExtraConditions) { |
231 | 265 | if ($alias) { |
|
0 commit comments