Skip to content

Commit

Permalink
feat(QuickBuilder): Prevent duplicate joins by default
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
elpete committed May 4, 2020
1 parent a480ef2 commit a8ac022
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
10 changes: 3 additions & 7 deletions ModuleConfig.cfc
Expand Up @@ -8,7 +8,8 @@ component {

function configure() {
settings = {
defaultGrammar = "AutoDiscover@qb"
"defaultGrammar" = "AutoDiscover@qb",
"preventDuplicateJoins" = true
};

interceptorSettings = {
Expand All @@ -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" );
}
Expand Down
6 changes: 2 additions & 4 deletions box.json
Expand Up @@ -49,9 +49,7 @@
"**/.*",
"test",
"tests",
".engine",
".travis.yml",
".gitignore",
"server.json"
"server.json",
"quick300.png"
]
}
13 changes: 7 additions & 6 deletions models/QuickBuilder.cfc
Expand Up @@ -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() );
Expand Down

0 comments on commit a8ac022

Please sign in to comment.