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

Pass $mode into the has/doesn't have query builder methods #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

csterling76
Copy link

@csterling76 csterling76 commented Mar 13, 2018

This pull request changes the builder method calls to account for the $mode parameter.

->whereDoesntHave() uses ->doesntHave() under the hood (https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Builder.php#L722) which allows passing an "or" or "and" value. Laravel calls this the 'operator'. This package calls this the 'mode'.

->whereHas() uses ->has() under the hood (https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Builder.php#L710) which allows passing the operator/mode.

The intended behavior when passing ?mode=or is that ALL filters are applied in DISJUNCTION. Currently, the behavior is using mode=or for parameters that exist on the model and mode=and for relation parameters which is unintended.

Currently, the behavior is the following
?user:first_name=John&user:last_name=Smith&mode=or
select * from providers where (exists (select * from users where providers.user_id = users.id and (first_name = John)) AND exists (select * from users where providers.user_id = users.id and (last_name = 'Smith')))

This pull request will change the query to the following
?user:first_name=John&user:last_name=Smith&mode=or
select * from providers where (exists (select * from users where providers.user_id = users.id and (first_name = John)) OR exists (select * from users where providers.user_id = users.id and (last_name = 'Smith')))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant