diff --git a/models/QuickBuilder.cfc b/models/QuickBuilder.cfc index 3e0d798e..2c09c6a1 100644 --- a/models/QuickBuilder.cfc +++ b/models/QuickBuilder.cfc @@ -476,12 +476,10 @@ component accessors="true" transientCache="false" { arguments.onFalse( this ); } } else { + var selectedCallback = arguments.condition ? arguments.onTrue : arguments.onFalse; + var builder = this; variables.qb.withScoping( function() { - if ( condition ) { - onTrue( this ); - } else { - onFalse( this ); - } + selectedCallback( builder ); } ); } @@ -990,7 +988,17 @@ component accessors="true" transientCache="false" { return result; } - return javacast( "null", "" ); + throw( + type = "QuickMissingMethod", + message = arrayToList( + [ + "Quick couldn't figure out what to do with [#arguments.missingMethodName#].", + "We tried checking columns, aliases, scopes, and relationships locally.", + "We also forwarded the call on to qb to see if it could do anything with it, but it couldn't." + ], + " " + ) + ); } /** diff --git a/models/QuickQB.cfc b/models/QuickQB.cfc index b1a15826..7c7f1241 100644 --- a/models/QuickQB.cfc +++ b/models/QuickQB.cfc @@ -1007,7 +1007,31 @@ component return result; } - return super.onMissingMethod( argumentCollection = arguments ); + var qbResult = javacast( "null", "" ); + var qbError = {}; + try { + qbResult = super.onMissingMethod( argumentCollection = arguments ); + } catch ( QBMissingMethod e ) { + qbError = e; + } + + if ( !isNull( qbResult ) ) { + return qbResult; + } + + throw( + type = "QuickMissingMethod", + message = arrayToList( + [ + "Quick couldn't figure out what to do with [#arguments.missingMethodName#].", + qbError.keyExists( "message" ) ? "The error returned was: #qbError.message#" : "qb did not return a result.", + "We tried checking columns, aliases, scopes, and relationships locally.", + "We also forwarded the call on to qb to see if it could do anything with it, but it couldn't." + ], + " " + ), + extendedInfo = serializeJSON( qbError ) + ); } // override's super impl diff --git a/tests/specs/integration/BaseEntity/ScopeSpec.cfc b/tests/specs/integration/BaseEntity/ScopeSpec.cfc index ef9708c2..2e7738e9 100644 --- a/tests/specs/integration/BaseEntity/ScopeSpec.cfc +++ b/tests/specs/integration/BaseEntity/ScopeSpec.cfc @@ -2,6 +2,21 @@ component extends="tests.resources.ModuleIntegrationSpec" { function run() { describe( "Scope Spec", function() { + it( "surfaces the missing method inside a when callback", function() { + try { + getInstance( "User" ).when( true, function( q ) { + q.missingScopeInsideWhen(); + } ); + } catch ( any e ) { + expect( e.type ).toBe( "QuickMissingMethod" ); + expect( e.message ).toInclude( "[missingScopeInsideWhen]" ); + expect( e.message ).notToInclude( "[when]" ); + return; + } + + fail( "Expected a QuickMissingMethod exception" ); + } ); + it( "looks for missing methods as scopes", function() { var users = getInstance( "User" ).latest().get(); expect( users ).toHaveLength( 5, "Five users should exist in the database and be returned." );