From a8ac02207b2b7125a11fd4b9ba60ed44ebcfbdbc Mon Sep 17 00:00:00 2001 From: Eric Peterson Date: Mon, 4 May 2020 10:49:00 -0600 Subject: [PATCH] feat(QuickBuilder): Prevent duplicate joins by default Using QueryBuilder's new feature, Quick will prevent duplicate joins by default. This allows you to safely add multiple joins in different scopes without having to check yourself. (Note that different table aliases will not match and will both be added.) BREAKING CHANGE: Duplicate joins will now be prevented by default. This can be changed in the moduleSettings by setting `preventDuplicateJoins: false` --- ModuleConfig.cfc | 10 +++------- box.json | 6 ++---- models/QuickBuilder.cfc | 13 +++++++------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/ModuleConfig.cfc b/ModuleConfig.cfc index 39eff104..f9e72798 100644 --- a/ModuleConfig.cfc +++ b/ModuleConfig.cfc @@ -8,7 +8,8 @@ component { function configure() { settings = { - defaultGrammar = "AutoDiscover@qb" + "defaultGrammar" = "AutoDiscover@qb", + "preventDuplicateJoins" = true }; interceptorSettings = { @@ -34,15 +35,10 @@ component { } function onLoad() { - binder.map( "QuickQB@quick" ) - .to( "qb.models.Query.QueryBuilder" ) - .initArg( name = "grammar", dsl = settings.defaultGrammar ) - .initArg( name = "utils", dsl = "QueryUtils@qb" ) - .initArg( name = "returnFormat", value = "array" ); - binder.map( alias = "QuickBuilder@quick", force = true ) .to( "#moduleMapping#.models.QuickBuilder" ) .initArg( name = "grammar", dsl = settings.defaultGrammar ) + .initArg( name = "preventDuplicateJoins", value = settings.preventDuplicateJoins ) .initArg( name = "utils", dsl = "QueryUtils@qb" ) .initArg( name = "returnFormat", value = "array" ); } diff --git a/box.json b/box.json index 1ce3c82c..7d1f065d 100644 --- a/box.json +++ b/box.json @@ -49,9 +49,7 @@ "**/.*", "test", "tests", - ".engine", - ".travis.yml", - ".gitignore", - "server.json" + "server.json", + "quick300.png" ] } diff --git a/models/QuickBuilder.cfc b/models/QuickBuilder.cfc index f5436a07..e63a3c63 100644 --- a/models/QuickBuilder.cfc +++ b/models/QuickBuilder.cfc @@ -610,12 +610,13 @@ component extends="qb.models.Query.QueryBuilder" accessors="true" { */ public QuickBuilder function newQuery() { var builder = new quick.models.QuickBuilder( - grammar = getGrammar(), - utils = getUtils(), - returnFormat = getReturnFormat(), - paginationCollector = isNull( variables.paginationCollector ) ? javacast( "null", "" ) : variables.paginationCollector, - columnFormatter = isNull( getColumnFormatter() ) ? javacast( "null", "" ) : getColumnFormatter(), - defaultOptions = getDefaultOptions() + grammar = getGrammar(), + utils = getUtils(), + returnFormat = getReturnFormat(), + paginationCollector = isNull( variables.paginationCollector ) ? javacast( "null", "" ) : variables.paginationCollector, + columnFormatter = isNull( getColumnFormatter() ) ? javacast( "null", "" ) : getColumnFormatter(), + defaultOptions = getDefaultOptions(), + preventDuplicateJoins = getPreventDuplicateJoins() ); builder.setEntity( getEntity() ); builder.setFrom( getEntity().tableName() );