diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b3624859ce0c..1e8169aeb7f3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -86,7 +86,7 @@ jobs: command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit --display-deprecation + run: vendor/bin/phpunit --display-deprecation ${{ matrix.stability == 'prefer-stable' && '--fail-on-deprecation' || '' }} env: DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root diff --git a/composer.json b/composer.json index b035062f8f4c..971aa5c0b257 100644 --- a/composer.json +++ b/composer.json @@ -105,7 +105,7 @@ "league/flysystem-path-prefixing": "^3.3", "league/flysystem-read-only": "^3.3", "league/flysystem-sftp-v3": "^3.0", - "mockery/mockery": "^1.6", + "mockery/mockery": "^1.6.10", "nyholm/psr7": "^1.2", "orchestra/testbench-core": "^9.5", "pda/pheanstalk": "^5.0", diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php b/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php index bd4dd77b5c78..c62132a26185 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php @@ -312,7 +312,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null * @param string $name * @param string $type * @param string $id - * @param string $ownerKey + * @param string|null $ownerKey * @return \Illuminate\Database\Eloquent\Relations\MorphTo<\Illuminate\Database\Eloquent\Model, $this> */ protected function morphEagerTo($name, $type, $id, $ownerKey) @@ -352,7 +352,7 @@ protected function morphInstanceTo($target, $name, $type, $id, $ownerKey) * @param \Illuminate\Database\Eloquent\Builder $query * @param TDeclaringModel $parent * @param string $foreignKey - * @param string $ownerKey + * @param string|null $ownerKey * @param string $type * @param string $relation * @return \Illuminate\Database\Eloquent\Relations\MorphTo diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php index 7822de3c2ad0..387ccc7ab33f 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php @@ -96,9 +96,9 @@ public function addConstraints() // For belongs to relationships, which are essentially the inverse of has one // or has many relationships, we need to actually query on the primary key // of the related models matching on the foreign key that's on a parent. - $key = $this->getQualifiedOwnerKeyName(); + $table = $this->related->getTable(); - $this->query->where($key, '=', $this->getForeignKeyFrom($this->child)); + $this->query->where($table.'.'.$this->ownerKey, '=', $this->getForeignKeyFrom($this->child)); } } @@ -108,7 +108,7 @@ public function addEagerConstraints(array $models) // We'll grab the primary key name of the related models since it could be set to // a non-standard name and not "id". We will then construct the constraint for // our eagerly loading query so it returns the proper models from execution. - $key = $this->getQualifiedOwnerKeyName(); + $key = $this->related->getTable().'.'.$this->ownerKey; $whereIn = $this->whereInMethod($this->related, $this->ownerKey); diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php index ecda194d0b8b..bd3e662be24b 100644 --- a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php @@ -25,6 +25,13 @@ class MorphTo extends BelongsTo */ protected $morphType; + /** + * The associated key on the parent model. + * + * @var string|null + */ + protected $ownerKey; + /** * The models whose relations are being eager loaded. * @@ -73,7 +80,7 @@ class MorphTo extends BelongsTo * @param \Illuminate\Database\Eloquent\Builder $query * @param TDeclaringModel $parent * @param string $foreignKey - * @param string $ownerKey + * @param string|null $ownerKey * @param string $type * @param string $relation * @return void diff --git a/tests/Database/DatabaseEloquentBelongsToTest.php b/tests/Database/DatabaseEloquentBelongsToTest.php index 750a1f0237fd..1ace437a4346 100755 --- a/tests/Database/DatabaseEloquentBelongsToTest.php +++ b/tests/Database/DatabaseEloquentBelongsToTest.php @@ -404,7 +404,6 @@ protected function getRelation($parent = null, $keyType = 'int') $this->related->shouldReceive('getKeyType')->andReturn($keyType); $this->related->shouldReceive('getKeyName')->andReturn('id'); $this->related->shouldReceive('getTable')->andReturn('relation'); - $this->related->shouldReceive('qualifyColumn')->andReturnUsing(fn (string $column) => "relation.{$column}"); $this->builder->shouldReceive('getModel')->andReturn($this->related); $parent = $parent ?: new EloquentBelongsToModelStub; diff --git a/tests/Database/DatabaseEloquentMorphToTest.php b/tests/Database/DatabaseEloquentMorphToTest.php index d85b4bf15b06..0366126f450c 100644 --- a/tests/Database/DatabaseEloquentMorphToTest.php +++ b/tests/Database/DatabaseEloquentMorphToTest.php @@ -368,7 +368,6 @@ protected function getRelationAssociate($parent) $related = m::mock(Model::class); $related->shouldReceive('getKey')->andReturn(1); $related->shouldReceive('getTable')->andReturn('relation'); - $related->shouldReceive('qualifyColumn')->andReturnUsing(fn (string $column) => "relation.{$column}"); $builder->shouldReceive('getModel')->andReturn($related); return new MorphTo($builder, $parent, 'foreign_key', 'id', 'morph_type', 'relation'); @@ -379,9 +378,8 @@ public function getRelation($parent = null, $builder = null) $this->builder = $builder ?: m::mock(Builder::class); $this->builder->shouldReceive('where')->with('relation.id', '=', 'foreign.value'); $this->related = m::mock(Model::class); - $this->related->shouldReceive('getcolumn')->andReturn('id'); + $this->related->shouldReceive('getKeyName')->andReturn('id'); $this->related->shouldReceive('getTable')->andReturn('relation'); - $this->related->shouldReceive('qualifyColumn')->andReturnUsing(fn (string $column) => "relation.{$column}"); $this->builder->shouldReceive('getModel')->andReturn($this->related); $parent = $parent ?: new EloquentMorphToModelStub;