From df91b8720ae1b71b8687b027af2b5c2f4f094953 Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Sat, 22 Aug 2026 06:36:12 -0600 Subject: [PATCH] Add without for configured eager loads Closes #48 --- models/QuickBuilder.cfc | 25 +++++++++++++++++++ .../Relationships/EagerLoadingSpec.cfc | 12 +++++++++ 2 files changed, 37 insertions(+) diff --git a/models/QuickBuilder.cfc b/models/QuickBuilder.cfc index 3e0d798e..06eb0c82 100644 --- a/models/QuickBuilder.cfc +++ b/models/QuickBuilder.cfc @@ -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 diff --git a/tests/specs/integration/BaseEntity/Relationships/EagerLoadingSpec.cfc b/tests/specs/integration/BaseEntity/Relationships/EagerLoadingSpec.cfc index f9024786..1a048f87 100644 --- a/tests/specs/integration/BaseEntity/Relationships/EagerLoadingSpec.cfc +++ b/tests/specs/integration/BaseEntity/Relationships/EagerLoadingSpec.cfc @@ -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", () => {