Skip to content

Commit

Permalink
Merge pull request #27 from Weebly/wherein-subquery
Browse files Browse the repository at this point in the history
Wherein subquery
  • Loading branch information
khepin authored Jan 22, 2020
2 parents 8b8f756 + fd26756 commit 7b20796
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"keywords": ["laravel", "eloquent", "uuid", "encrypt", "database"],
"require": {
"ramsey/uuid": "~3.0",
"illuminate/database": "~6.0",
"illuminate/support": "~6.0",
"illuminate/encryption": "~6.0"
"illuminate/database": ">=5.0 <7.0.0",
"illuminate/support": ">=5.0 <7.0.0",
"illuminate/encryption": ">=5.0 <7.0.0"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0",
"laravel/framework": "6.*",
"orchestra/testbench": "~4.0"
"orchestra/testbench": ">=3.0 <5.0.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 5 additions & 1 deletion src/Database/EloquentBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ public function whereIn($column, $values, $boolean = 'and', $not = false)
// Loop over all values and mutate them
$mutatedValues = [];
foreach ($where['values'] as $value) {
$mutatedValues[] = $this->model->serializeAttribute($mutatedColumn, $value);
if ($value instanceof Expression) {
$mutatedValues[] = $value;
} else {
$mutatedValues[] = $this->model->serializeAttribute($mutatedColumn, $value);
}
}

// Modify the values
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/MutatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ public function test_where_in()
$this->assertEquals(2, $p->count());
}

public function test_where_in_subquery()
{
$id = Uuid::uuid1()->toString();
$id2 = Uuid::uuid1()->toString();
(new TestModel())->create(['id' => $id, 'name' => 'A chair']);
(new TestModel())->create(['id' => $id2, 'name' => 'A table']);
$p = TestModel::whereIn('id', function ($query) {
$query->select('id')->from('test_model');
})->get();
$this->assertEquals(2, $p->count());
$this->assertEquals($id, $p->first()->id);
$this->assertEquals($id2, $p->last()->id);
}

public function test_where_not_in()
{
$id = Uuid::uuid1()->toString();
Expand Down

0 comments on commit 7b20796

Please sign in to comment.