Another quick issue. I am trying to apply a where ...
# box-products
r
Another quick issue. I am trying to apply a where filter on my entity without using method chaining. if I do not chain the methods quick will not apply the where clause. I feel like I am missing something obvious. @sknowlton
Copy code
// 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);
@elpete this seems to be a regression in v5. I have opened an issue on github
@sknowlton could you test to see if I’m going mad?
e
This is explainable, at least.
Copy code
// entity is a BaseEntity instance
var entity = getInstance('Device')
;
Copy code
// entity is still a BaseEntity instance
// but it returned a new QuickBuilder
var builder = local.entity.where('id',4);
// to get the desired result
Copy code
you need to keep that QuickBuilder object around
var result = builder.get();
writeDump(var=result, top=2);
r
Aha. Thanks!
@elpete what do you think of this solution. In the
forwardToQB
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?
Copy code
BaseEntity.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
		);
	}
e
I’m not sure. We used to have the entity store the builder but ran into performance problems with that.
r
I dont think this should cause any performance issues. Looking at the old code, the builder was injected everytime a an entity was instantiated. This way the builder is still only created when you need it. I ran a quick test and performance numbers are the same.