Skip to content

Commit cfd1693

Browse files
committed
Merge branch 'where-in-raw' of https://github.com/staudenmeir/framework into staudenmeir-where-in-raw
2 parents abd5962 + d10b0a5 commit cfd1693

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ protected function whereInMethod(Model $model, $key)
318318
{
319319
return $model->getKeyName() === last(explode('.', $key))
320320
&& in_array($model->getKeyType(), ['int', 'integer'])
321-
? 'whereInRaw'
321+
? 'whereInRawInt'
322322
: 'whereIn';
323323
}
324324

src/Illuminate/Database/Query/Builder.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,23 +949,25 @@ protected function whereInExistingQuery($column, $query, $boolean, $not)
949949
}
950950

951951
/**
952-
* Add a "where in raw" clause to the query.
952+
* Add a "where in raw" clause for integer values to the query.
953953
*
954954
* @param string $column
955-
* @param array $values
955+
* @param \Illuminate\Contracts\Support\Arrayable|array $values
956956
* @param string $boolean
957-
* @param bool $not
957+
* @param bool $not
958958
* @return $this
959959
*/
960-
public function whereInRaw($column, array $values, $boolean = 'and', $not = false)
960+
public function whereInRawInt($column, $values, $boolean = 'and', $not = false)
961961
{
962962
$type = $not ? 'NotInRaw' : 'InRaw';
963963

964964
if ($values instanceof Arrayable) {
965965
$values = $values->toArray();
966966
}
967967

968-
$values = array_map('intval', $values);
968+
foreach ($values as &$value) {
969+
$value = (int) $value;
970+
}
969971

970972
$this->wheres[] = compact('type', 'column', 'values', 'boolean');
971973

tests/Database/DatabaseEloquentBelongsToTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function testEagerConstraintsAreProperlyAdded()
8181
$relation = $this->getRelation();
8282
$relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
8383
$relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
84-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', ['foreign.value', 'foreign.value.two']);
84+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('relation.id', ['foreign.value', 'foreign.value.two']);
8585
$models = [new EloquentBelongsToModelStub, new EloquentBelongsToModelStub, new AnotherEloquentBelongsToModelStub];
8686
$relation->addEagerConstraints($models);
8787
}
@@ -91,7 +91,7 @@ public function testIdsInEagerConstraintsCanBeZero()
9191
$relation = $this->getRelation();
9292
$relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
9393
$relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
94-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', ['foreign.value', 0]);
94+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('relation.id', ['foreign.value', 0]);
9595
$models = [new EloquentBelongsToModelStub, new EloquentBelongsToModelStubWithZeroId];
9696
$relation->addEagerConstraints($models);
9797
}
@@ -160,7 +160,7 @@ public function testDefaultEagerConstraintsWhenIncrementing()
160160
$relation = $this->getRelation();
161161
$relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
162162
$relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
163-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', m::mustBe([null]));
163+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('relation.id', m::mustBe([null]));
164164
$models = [new MissingEloquentBelongsToModelStub, new MissingEloquentBelongsToModelStub];
165165
$relation->addEagerConstraints($models);
166166
}
@@ -178,7 +178,7 @@ public function testDefaultEagerConstraintsWhenNotIncrementing()
178178
$relation = $this->getRelation(null, false);
179179
$relation->getRelated()->shouldReceive('getKeyName')->andReturn('id');
180180
$relation->getRelated()->shouldReceive('getKeyType')->andReturn('int');
181-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('relation.id', m::mustBe([null]));
181+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('relation.id', m::mustBe([null]));
182182
$models = [new MissingEloquentBelongsToModelStub, new MissingEloquentBelongsToModelStub];
183183
$relation->addEagerConstraints($models);
184184
}

tests/Database/DatabaseEloquentHasManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public function testEagerConstraintsAreProperlyAdded()
202202
$relation = $this->getRelation();
203203
$relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
204204
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
205-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.foreign_key', [1, 2]);
205+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('table.foreign_key', [1, 2]);
206206
$model1 = new EloquentHasManyModelStub;
207207
$model1->id = 1;
208208
$model2 = new EloquentHasManyModelStub;

tests/Database/DatabaseEloquentHasOneTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testEagerConstraintsAreProperlyAdded()
165165
$relation = $this->getRelation();
166166
$relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
167167
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
168-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.foreign_key', [1, 2]);
168+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('table.foreign_key', [1, 2]);
169169
$model1 = new EloquentHasOneModelStub;
170170
$model1->id = 1;
171171
$model2 = new EloquentHasOneModelStub;

tests/Database/DatabaseEloquentMorphTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testMorphManyEagerConstraintsAreProperlyAdded()
5454
$relation = $this->getManyRelation();
5555
$relation->getParent()->shouldReceive('getKeyName')->once()->andReturn('id');
5656
$relation->getParent()->shouldReceive('getKeyType')->once()->andReturn('int');
57-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('table.morph_id', [1, 2]);
57+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('table.morph_id', [1, 2]);
5858
$relation->getQuery()->shouldReceive('where')->once()->with('table.morph_type', get_class($relation->getParent()));
5959

6060
$model1 = new EloquentMorphResetModelStub;

tests/Database/DatabaseEloquentMorphToManyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function testEagerConstraintsAreProperlyAdded()
2020
$relation = $this->getRelation();
2121
$relation->getParent()->shouldReceive('getKeyName')->andReturn('id');
2222
$relation->getParent()->shouldReceive('getKeyType')->andReturn('int');
23-
$relation->getQuery()->shouldReceive('whereInRaw')->once()->with('taggables.taggable_id', [1, 2]);
23+
$relation->getQuery()->shouldReceive('whereInRawInt')->once()->with('taggables.taggable_id', [1, 2]);
2424
$relation->getQuery()->shouldReceive('where')->once()->with('taggables.taggable_type', get_class($relation->getParent()));
2525
$model1 = new EloquentMorphToManyModelStub;
2626
$model1->id = 1;

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,10 @@ public function testEmptyWhereNotIns()
693693
$this->assertEquals([0 => 1], $builder->getBindings());
694694
}
695695

696-
public function testWhereInRaw()
696+
public function testWhereInRawInt()
697697
{
698698
$builder = $this->getBuilder();
699-
$builder->select('*')->from('users')->whereInRaw('id', ['1a', 2]);
699+
$builder->select('*')->from('users')->whereInRawInt('id', ['1a', 2]);
700700
$this->assertEquals('select * from "users" where "id" in (1, 2)', $builder->toSql());
701701
$this->assertEquals([], $builder->getBindings());
702702
}

0 commit comments

Comments
 (0)