Skip to content

Commit

Permalink
fix(QueryBuilder): Prefer the parent query over magic methods
Browse files Browse the repository at this point in the history
If a parent query has been set, and a missing method is
found on the parent query, then call it before trying the
magic `where` methods.  This does not change the final try
to the parent query if no methods match.  That is still attempted
which allows the parent query to try `onMissingMethod` magic.
  • Loading branch information
elpete committed Feb 28, 2020
1 parent 3049de2 commit f9fd8d1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions models/Query/QueryBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,15 @@ component displayname="QueryBuilder" accessors="true" {
* @return any
*/
public any function onMissingMethod( string missingMethodName, struct missingMethodArguments ) {
/*
* If a parent query has been set, and has this exact method name,
* forward on the method call to the parent query.
*/
if ( !isNull( variables.parentQuery ) && structKeyExists( variables.parentQuery, missingMethodName ) ) {
return invoke( variables.parentQuery.populateQuery( this ), missingMethodName, missingMethodArguments );
}


/*
* This block handles dynamic `andWhere` methods.
* If the method exists without the `and` we route the call there.
Expand Down

0 comments on commit f9fd8d1

Please sign in to comment.