Skip to content
Open
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
25 changes: 25 additions & 0 deletions models/QuickBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,31 @@ component accessors="true" transientCache="false" {
return this;
}

/**
* Removes one or more relationships from the eager-load list. Omitting the
* argument removes every configured eager load.
*
* @relationName A relationship name or array of relationship names to remove.
*
* @return QuickBuilder
*/
public any function without( any relationName ) {
if ( isNull( arguments.relationName ) ) {
variables._eagerLoad = [];
return this;
}

var exclusions = arrayWrap( arguments.relationName );
variables._eagerLoad = variables._eagerLoad.filter( function( eagerLoad ) {
var path = isStruct( arguments.eagerLoad ) ? arguments.eagerLoad.keyArray()[ 1 ] : arguments.eagerLoad;
return !exclusions.some( function( exclusion ) {
return compareNoCase( path, exclusion ) == 0 ||
compareNoCase( left( path, len( exclusion ) + 1 ), exclusion & "." ) == 0;
} );
} );
return this;
}

/**
* Eager loads the configured relations for the retrieved entities.
* Returns the retrieved entities eager loaded with the configured
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,18 @@ component extends="tests.resources.ModuleIntegrationSpec" {
);
}
} );

it( "can disable an automatically eager loaded relationship", () => {
var posts = getInstance( "EagerLoadedPost" )
.without( "comments" )
.preventLazyLoading()
.get();

expect( posts ).toHaveLength( 4 );
expect( posts[ 1 ].isRelationshipLoaded( "comments" ) ).toBeFalse();
expect( () => posts[ 1 ].getComments() ).toThrow( type = "QuickLazyLoadingException" );
expect( variables.queries ).toHaveLength( 1, "Only the posts query should execute." );
} );
} );

describe( "multiple nested eager loads", () => {
Expand Down
Loading