Ryan Albrecht
10/12/2022, 9:27 PM// this does work
var entity = getInstance('Device').where('id',4);
// this does NOT work
var entity = getInstance('Device')
local.entity.where('id',4);
//get the result
var result = entity.get();
writeDump(var=result, top=2);
Ryan Albrecht
10/12/2022, 9:44 PMRyan Albrecht
10/12/2022, 9:49 PMelpete
10/12/2022, 10:02 PM// entity is a BaseEntity instance
var entity = getInstance('Device')
;
// entity is still a BaseEntity instance
// but it returned a new QuickBuilder
var builder = local.entity.where('id',4);
// to get the desired result
you need to keep that QuickBuilder object around
var result = builder.get();
writeDump(var=result, top=2);
Ryan Albrecht
10/13/2022, 12:23 PMRyan Albrecht
10/13/2022, 3:45 PMforwardToQB
method instead of directly instantiating a new QuickBuilder
instance you check if it exists on the entity. If it does return it. If not then create it, store in the entity then return it?Ryan Albrecht
10/13/2022, 3:46 PMBaseEntity.cfc
/**
* If the quickbuilder instance exists, then return it, else create it, cache it and return it
*
* @return quick.models.QuickBuilder
*/
public any function getQuickBuilder() {
if(!isDefined('variables._quickBuilder')){
variables._quickBuilder = newQuery();
}
return variables._quickBuilder;
}
/**
* Forwards a missing method call on to qb.
*
* @missingMethodName The potential scope name.
* @missingMethodArguments Any arguments to pass to the potential scope.
*
* @return any
*/
private any function forwardToQB( required string missingMethodName, struct missingMethodArguments = {} ) {
return invoke(
//create the builder instance if it has not be instantiated yet
getQuickBuilder(),
arguments.missingMethodName,
arguments.missingMethodArguments
);
}
elpete
10/13/2022, 9:28 PMRyan Albrecht
10/13/2022, 10:39 PMRyan Albrecht
10/13/2022, 11:35 PM