Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Fix belongsToMany->wherePivot condition for boolean columns #28252

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,11 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
// If the operator is a literal string 'in' or 'not in', we will assume that
// the developer wants to use the "whereIn / whereNotIn" methods for this
// operation and proxy the query through those methods from this point.
if ($operator == 'in') {
if ($operator === 'in') {
return $this->whereIn($column, $value, $boolean);
}

if ($operator == 'not in') {
if ($operator === 'not in') {
return $this->whereNotIn($column, $value, $boolean);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Integration/Database/EloquentBelongsToManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,24 @@ public function test_global_scope_columns()

$this->assertEquals(['id' => 1], $tags[0]->getAttributes());
}

public function test_where_pivot_with_boolean_column_query()
{
Schema::table('posts_tags', function (Blueprint $table) {
$table->boolean('primary')->default(false)->after('flag');
});

$tag = Tag::create(['name' => Str::random()]);
$post = Post::create(['title' => Str::random()]);

DB::table('posts_tags')->insert([
['post_id' => $post->id, 'tag_id' => $tag->id, 'primary' => true]
]);

$relationTag = $post->tags()->wherePivot('primary', true)->first();

$this->assertEquals($relationTag->getAttributes(), $tag->getAttributes());
}
}

class Post extends Model
Expand Down