From 3a0e280f5c0e018a67e24eed650df5f3be63dc6a Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Nov 2024 08:35:04 +0800 Subject: [PATCH 1/6] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b3624859ce0c..d6152d51c098 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 t ${{ 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", From 9e218869996b84597618f7af96831021ae65056d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Nov 2024 08:43:16 +0800 Subject: [PATCH 2/6] wip Signed-off-by: Mior Muhammad Zaki --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d6152d51c098..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 t ${{ matrix.stability == 'prefer-stable' && '--fail-on-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 From 82798ca6a437cafa69e5656a513918fe5e13feb1 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Nov 2024 09:02:01 +0800 Subject: [PATCH 3/6] Revert "fix: use qualifyColumn rather than assuming format (#53559)" This reverts commit cff895dd2bc01145bf26e55e002f651b76814df7. --- src/Illuminate/Database/Eloquent/Relations/BelongsTo.php | 6 +++--- tests/Database/DatabaseEloquentBelongsToTest.php | 1 - tests/Database/DatabaseEloquentMorphToTest.php | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) 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/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; From c61e0fcf1f3a57175bb29862a8e66cbf4c50136c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Nov 2024 09:08:13 +0800 Subject: [PATCH 4/6] wip Signed-off-by: Mior Muhammad Zaki --- .../Database/Eloquent/Concerns/HasRelationships.php | 4 ++-- src/Illuminate/Database/Eloquent/Model.php | 2 +- src/Illuminate/Database/Eloquent/Relations/MorphTo.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 7afa59933416..8babbfedecc2 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -583,7 +583,7 @@ public function forceFill(array $attributes) * @param string $column * @return string */ - public function qualifyColumn($column) + public function qualifyColumn(string $column) { if (str_contains($column, '.')) { return $column; diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php index ecda194d0b8b..f24810119c84 100644 --- a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php @@ -73,7 +73,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 From bfdee3584ca5e190a61557ba40cab82fdb5cc967 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Nov 2024 09:08:38 +0800 Subject: [PATCH 5/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Database/Eloquent/Model.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Eloquent/Model.php b/src/Illuminate/Database/Eloquent/Model.php index 8babbfedecc2..7afa59933416 100644 --- a/src/Illuminate/Database/Eloquent/Model.php +++ b/src/Illuminate/Database/Eloquent/Model.php @@ -583,7 +583,7 @@ public function forceFill(array $attributes) * @param string $column * @return string */ - public function qualifyColumn(string $column) + public function qualifyColumn($column) { if (str_contains($column, '.')) { return $column; From 6fede04e2e886dfd57bbd0a04528eb3753626d5d Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 19 Nov 2024 09:13:05 +0800 Subject: [PATCH 6/6] wip Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Database/Eloquent/Relations/MorphTo.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Relations/MorphTo.php b/src/Illuminate/Database/Eloquent/Relations/MorphTo.php index f24810119c84..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. *