Skip to content

Commit 30ddaef

Browse files
authored
Revert "fix: use qualifyColumn rather than assuming format (#53559)" (#53568)
* wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * Revert "fix: use qualifyColumn rather than assuming format (#53559)" This reverts commit cff895d. * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 4d2d04e commit 30ddaef

File tree

7 files changed

+16
-12
lines changed

7 files changed

+16
-12
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
8787

8888
- name: Execute tests
89-
run: vendor/bin/phpunit --display-deprecation
89+
run: vendor/bin/phpunit --display-deprecation ${{ matrix.stability == 'prefer-stable' && '--fail-on-deprecation' || '' }}
9090
env:
9191
DB_PORT: ${{ job.services.mysql.ports[3306] }}
9292
DB_USERNAME: root

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"league/flysystem-path-prefixing": "^3.3",
106106
"league/flysystem-read-only": "^3.3",
107107
"league/flysystem-sftp-v3": "^3.0",
108-
"mockery/mockery": "^1.6",
108+
"mockery/mockery": "^1.6.10",
109109
"nyholm/psr7": "^1.2",
110110
"orchestra/testbench-core": "^9.5",
111111
"pda/pheanstalk": "^5.0",

src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null
312312
* @param string $name
313313
* @param string $type
314314
* @param string $id
315-
* @param string $ownerKey
315+
* @param string|null $ownerKey
316316
* @return \Illuminate\Database\Eloquent\Relations\MorphTo<\Illuminate\Database\Eloquent\Model, $this>
317317
*/
318318
protected function morphEagerTo($name, $type, $id, $ownerKey)
@@ -352,7 +352,7 @@ protected function morphInstanceTo($target, $name, $type, $id, $ownerKey)
352352
* @param \Illuminate\Database\Eloquent\Builder<TRelatedModel> $query
353353
* @param TDeclaringModel $parent
354354
* @param string $foreignKey
355-
* @param string $ownerKey
355+
* @param string|null $ownerKey
356356
* @param string $type
357357
* @param string $relation
358358
* @return \Illuminate\Database\Eloquent\Relations\MorphTo<TRelatedModel, TDeclaringModel>

src/Illuminate/Database/Eloquent/Relations/BelongsTo.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public function addConstraints()
9696
// For belongs to relationships, which are essentially the inverse of has one
9797
// or has many relationships, we need to actually query on the primary key
9898
// of the related models matching on the foreign key that's on a parent.
99-
$key = $this->getQualifiedOwnerKeyName();
99+
$table = $this->related->getTable();
100100

101-
$this->query->where($key, '=', $this->getForeignKeyFrom($this->child));
101+
$this->query->where($table.'.'.$this->ownerKey, '=', $this->getForeignKeyFrom($this->child));
102102
}
103103
}
104104

@@ -108,7 +108,7 @@ public function addEagerConstraints(array $models)
108108
// We'll grab the primary key name of the related models since it could be set to
109109
// a non-standard name and not "id". We will then construct the constraint for
110110
// our eagerly loading query so it returns the proper models from execution.
111-
$key = $this->getQualifiedOwnerKeyName();
111+
$key = $this->related->getTable().'.'.$this->ownerKey;
112112

113113
$whereIn = $this->whereInMethod($this->related, $this->ownerKey);
114114

src/Illuminate/Database/Eloquent/Relations/MorphTo.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ class MorphTo extends BelongsTo
2525
*/
2626
protected $morphType;
2727

28+
/**
29+
* The associated key on the parent model.
30+
*
31+
* @var string|null
32+
*/
33+
protected $ownerKey;
34+
2835
/**
2936
* The models whose relations are being eager loaded.
3037
*
@@ -73,7 +80,7 @@ class MorphTo extends BelongsTo
7380
* @param \Illuminate\Database\Eloquent\Builder<TRelatedModel> $query
7481
* @param TDeclaringModel $parent
7582
* @param string $foreignKey
76-
* @param string $ownerKey
83+
* @param string|null $ownerKey
7784
* @param string $type
7885
* @param string $relation
7986
* @return void

tests/Database/DatabaseEloquentBelongsToTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ protected function getRelation($parent = null, $keyType = 'int')
404404
$this->related->shouldReceive('getKeyType')->andReturn($keyType);
405405
$this->related->shouldReceive('getKeyName')->andReturn('id');
406406
$this->related->shouldReceive('getTable')->andReturn('relation');
407-
$this->related->shouldReceive('qualifyColumn')->andReturnUsing(fn (string $column) => "relation.{$column}");
408407
$this->builder->shouldReceive('getModel')->andReturn($this->related);
409408
$parent = $parent ?: new EloquentBelongsToModelStub;
410409

tests/Database/DatabaseEloquentMorphToTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ protected function getRelationAssociate($parent)
368368
$related = m::mock(Model::class);
369369
$related->shouldReceive('getKey')->andReturn(1);
370370
$related->shouldReceive('getTable')->andReturn('relation');
371-
$related->shouldReceive('qualifyColumn')->andReturnUsing(fn (string $column) => "relation.{$column}");
372371
$builder->shouldReceive('getModel')->andReturn($related);
373372

374373
return new MorphTo($builder, $parent, 'foreign_key', 'id', 'morph_type', 'relation');
@@ -379,9 +378,8 @@ public function getRelation($parent = null, $builder = null)
379378
$this->builder = $builder ?: m::mock(Builder::class);
380379
$this->builder->shouldReceive('where')->with('relation.id', '=', 'foreign.value');
381380
$this->related = m::mock(Model::class);
382-
$this->related->shouldReceive('getcolumn')->andReturn('id');
381+
$this->related->shouldReceive('getKeyName')->andReturn('id');
383382
$this->related->shouldReceive('getTable')->andReturn('relation');
384-
$this->related->shouldReceive('qualifyColumn')->andReturnUsing(fn (string $column) => "relation.{$column}");
385383
$this->builder->shouldReceive('getModel')->andReturn($this->related);
386384
$parent = $parent ?: new EloquentMorphToModelStub;
387385

0 commit comments

Comments
 (0)