Skip to content

Commit

Permalink
Allow arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
gdebrauwer committed Jan 24, 2025
1 parent 717a88c commit e92c288
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public function orWhereMorphDoesntHaveRelation($relation, $types, $column, $oper
* Add a morph-to relationship condition to the query.
*
* @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection<int, \Illuminate\Database\Eloquent\Model>|string|null $model
* @param \Illuminate\Database\Eloquent\Model|Iterable<int, \Illuminate\Database\Eloquent\Model>|string|null $model
* @return $this
*/
public function whereMorphedTo($relation, $model, $boolean = 'and')
Expand Down Expand Up @@ -579,7 +579,7 @@ public function whereMorphedTo($relation, $model, $boolean = 'and')
* Add a not morph-to relationship condition to the query.
*
* @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection<int, \Illuminate\Database\Eloquent\Model>|string $model
* @param \Illuminate\Database\Eloquent\Model|Iterable<int, \Illuminate\Database\Eloquent\Model>|string $model
* @return $this
*/
public function whereNotMorphedTo($relation, $model, $boolean = 'and')
Expand Down Expand Up @@ -618,7 +618,7 @@ public function whereNotMorphedTo($relation, $model, $boolean = 'and')
* Add a morph-to relationship condition to the query with an "or where" clause.
*
* @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection<int, \Illuminate\Database\Eloquent\Model>|string|null $model
* @param \Illuminate\Database\Eloquent\Model|Iterable<int, \Illuminate\Database\Eloquent\Model>|string|null $model
* @return $this
*/
public function orWhereMorphedTo($relation, $model)
Expand All @@ -630,7 +630,7 @@ public function orWhereMorphedTo($relation, $model)
* Add a not morph-to relationship condition to the query with an "or where" clause.
*
* @param \Illuminate\Database\Eloquent\Relations\MorphTo<*, *>|string $relation
* @param \Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection<int, \Illuminate\Database\Eloquent\Model>|string $model
* @param \Illuminate\Database\Eloquent\Model|Iterable<int, \Illuminate\Database\Eloquent\Model>|string $model
* @return $this
*/
public function orWhereNotMorphedTo($relation, $model)
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ public function testWhereMorphedToCollectionWithDifferentModels()
$thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub;
$thirdRelatedModel->id = 3;

$builder = $model->whereMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]));
$builder = $model->whereMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]);

$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?)))', $builder->toSql());
$this->assertEquals([$firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings());
Expand Down Expand Up @@ -1869,7 +1869,7 @@ public function testWhereNotMorphedToCollectionWithDifferentModels()
$thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub;
$thirdRelatedModel->id = 3;

$builder = $model->whereNotMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]));
$builder = $model->whereNotMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]);

$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?)))', $builder->toSql());
$this->assertEquals([$firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings());
Expand Down Expand Up @@ -1920,7 +1920,7 @@ public function testOrWhereMorphedToCollectionWithDifferentModels()
$thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub;
$thirdRelatedModel->id = 3;

$builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]));
$builder = $model->where('bar', 'baz')->orWhereMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]);

$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or (("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" = ? and "eloquent_builder_test_model_parent_stubs"."morph_id" in (?)))', $builder->toSql());
$this->assertEquals(['baz', $firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings());
Expand Down Expand Up @@ -1982,7 +1982,7 @@ public function testOrWhereNotMorphedToCollectionWithDifferentModels()
$thirdRelatedModel = new EloquentBuilderTestModelCloseRelatedStub;
$thirdRelatedModel->id = 3;

$builder = $model->where('bar', 'baz')->orWhereNotMorphedTo('morph', new Collection([$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]));
$builder = $model->where('bar', 'baz')->orWhereNotMorphedTo('morph', [$firstRelatedModel, $secondRelatedModel, $thirdRelatedModel]);

$this->assertSame('select * from "eloquent_builder_test_model_parent_stubs" where "bar" = ? or not (("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?, ?)) or ("eloquent_builder_test_model_parent_stubs"."morph_type" <=> ? and "eloquent_builder_test_model_parent_stubs"."morph_id" not in (?)))', $builder->toSql());
$this->assertEquals(['baz', $firstRelatedModel->getMorphClass(), $firstRelatedModel->getKey(), $thirdRelatedModel->getKey(), $secondRelatedModel->getMorphClass(), $secondRelatedModel->id], $builder->getBindings());
Expand Down

0 comments on commit e92c288

Please sign in to comment.