Skip to content

Commit

Permalink
feat(QuickBuilder): Automatically scope whereHas and whereDoesntHave …
Browse files Browse the repository at this point in the history
…callbacks
  • Loading branch information
elpete committed Jul 23, 2020
1 parent 3183f6d commit 38b8a46
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" {
expect( users ).toHaveLength( 1 );
} );

it( "automatically groups where clauses with an OR combinator inside whereHas", function() {
var sql = getInstance( "User" )
.whereHas( "posts", function( q ) {
q.where( "body", "like", "%different%" ).orWhere( "title", "like", "%different%" );
} )
.retrieveQuery()
.toSQL();
expect( sql ).toBe(
"SELECT `users`.`city`, `users`.`country_id`, `users`.`created_date`, `users`.`email`, `users`.`externalID`, `users`.`favoritePost_id`, `users`.`first_name`, `users`.`id`, `users`.`last_name`, `users`.`modified_date`, `users`.`password`, `users`.`state`, `users`.`streetOne`, `users`.`streetTwo`, `users`.`team_id`, `users`.`type`, `users`.`username`, `users`.`zip` FROM `users` WHERE EXISTS (SELECT 1 FROM `my_posts` WHERE (`users`.`id` = `my_posts`.`user_id`) AND (`my_posts`.`body` LIKE ? OR `my_posts`.`title` LIKE ?))"
);
} );

it( "can constrain a has query using whereHas and orWhereHas", function() {
var users = getInstance( "User" )
.where( function( q ) {
Expand Down

0 comments on commit 38b8a46

Please sign in to comment.