Skip to content

Comments

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

Open
csterling76 wants to merge 1 commit intojedrzej:masterfrom
csterling76:issue_38_searching_related_models
Open

Pass $mode into the has/doesn't have query builder methods#39
csterling76 wants to merge 1 commit intojedrzej:masterfrom
csterling76:issue_38_searching_related_models

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