coldbox-modules / quick

A ColdBox ORM Engine
https://quick.ortusbooks.com
MIT License
23 stars 19 forks source link

Migrate from `retrieveQuery` to `asQuery` - compat issues #223

Closed davidAtInleague closed 1 year ago

davidAtInleague commented 1 year ago

Quick v6.2.0

QueryUtils@qb is used to determine if the runtime type of an object is a QueryBuilder; but, it is unable to detect a QuickBuilder.

utils = getInstance("QueryUtils@qb") 
entity = getInstance("qUser")
builder = entity.retrieveQuery()
quickBuilder = entity.asQuery()

// actual: true, false
writedump([utils.isBuilder(builder), utils.isBuilder(quickBuilder)])

This breaks at least the following pattern:

function scopeX( qb ) {
  qb.whereIn("column", getInstance("foo").something().asQuery()) // was retrieveQuery
}

With the error:

"The function [normalizeToArray] has an invalid return value , [Cannot cast Object type [Component quick.models.QuickBuilder] to a value of type [array]]"

Because:


public QueryBuilder function whereIn(
    column,
    values,
    combinator = "and",
    negate = false
) {
    if (
        isClosure( values ) ||
        isCustomFunction( values ) ||
        getUtils().isBuilder( values ) // <<<<<<< quickbuilder yields false
    ) {
        arguments.query = arguments.values;
        return whereInSub( argumentCollection = arguments );
    }

    arguments.values = normalizeToArray( arguments.values ); // <<<<<<< get here, but shouldn't

  ...
}