Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions models/QuickBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
} );
}

Expand Down Expand Up @@ -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."
],
" "
)
);
}

/**
Expand Down
26 changes: 25 additions & 1 deletion models/QuickQB.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions tests/specs/integration/BaseEntity/ScopeSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
Expand Down
Loading