Skip to content

orWhereNull inside whereHas disables the whereHas #17428

Closed
@tontonsb

Description

@tontonsb
  • Laravel Version: 5.1.45
  • PHP Version: 7.0
  • Database Driver & Version: MySQL, MariaDB Server 10.1.18

Description:

It seems to me that orWhereNull works incorrectly inside a whereHas. It seems to cancel all of whereHas effect.

Steps To Reproduce:

This was my code:

$items = Item::whereHas('owner', function($owner) {
	$owner->where('status', '=', 5)->orWhereNull('status');
})->get();

I got $items that contained all of the items regardless of owner's status.

I got the desired result by wrapping the conditions inside another closure like this:

$items = Item::whereHas('owner', function($owner) {
	$owner->where(function($o) {
		$o->where('status', '=', 5)->orWhereNull('status');
	});
})->get();

I am not sure if this is a bug or the intended behaviour, I just wanted to let you know in case this is an unknown error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions