Skip to content

Commit

Permalink
Revert "fix: use qualifyColumn rather than assuming format (#53559)" (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
crynobone authored Nov 19, 2024
1 parent 4d2d04e commit 30ddaef
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -352,7 +352,7 @@ protected function morphInstanceTo($target, $name, $type, $id, $ownerKey)
* @param \Illuminate\Database\Eloquent\Builder<TRelatedModel> $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<TRelatedModel, TDeclaringModel>
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Relations/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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);

Expand Down
9 changes: 8 additions & 1 deletion src/Illuminate/Database/Eloquent/Relations/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -73,7 +80,7 @@ class MorphTo extends BelongsTo
* @param \Illuminate\Database\Eloquent\Builder<TRelatedModel> $query
* @param TDeclaringModel $parent
* @param string $foreignKey
* @param string $ownerKey
* @param string|null $ownerKey
* @param string $type
* @param string $relation
* @return void
Expand Down
1 change: 0 additions & 1 deletion tests/Database/DatabaseEloquentBelongsToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 1 addition & 3 deletions tests/Database/DatabaseEloquentMorphToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;

Expand Down

0 comments on commit 30ddaef

Please sign in to comment.