[ColdBox-BE 4.0] ORMService - List as query with no results

I’ve got the following entities:

Business.cfc

`

component persistent=“true” table=“hier_Businesses” {
property name=“businessID” fieldType=“id” generator=“increment” ormtype=“integer”;
property name=“business”;
property name=“businessName”;
property name=“centers” fieldtype=“one-to-many” cfc=“Center” fkcolumn=“businessID” inverse=“true”;
}

`

Center.cfc

`

component persistent=“true” table=“hier_Centers” {
property name=“centerID” fieldType=“id” generator=“increment” ormtype=“integer”;
property name=“centerAbbr”;
property name=“center”;
property name=“def_start”;
property name=“def_end”;
property name=“tzStd”;
property name=“is24” type=“boolean”;
property name=“clrClass”;
property name=“dataInterval” type=“numeric”;
property name=“business” fieldtype=“many-to-one” cfc=“Business” fkcolumn=“businessID”;
}

`

I’m using Criteria Builder to filter Centers that match a certain Business.BusinessID like so:

`

property name=“businessService” inject=“entityService:Business”;
property name=“centerService” inject=“entityService:Center”;

// new Center criteria
local.c = centerService.newCriteria();

// restrict Center to specified Business
c.and(c.restrictions.eq(“business.businessID”, javaCast(“int”, rc.businessID)));

// list the Centers
local.q = c.list(asQuery=true);

`

When there are records, the query result set is as expected with the full column list and rows:

Query
Execution Time: 0 ms
Record Count: 3
Cached: No
Lazy: No

centerID centerAbbr center def_start def_end tzStd is24 clrClass dataInterval
1 1 NAO New Albany true true US/Eastern false green 60
2 2 PHX Phoenix true true US/Arizona false orange 60
3 3 LPK Lake Park true true US/Mountain false blue 60

However, if there are no results and I am listing as a query, the result set contains not only 0 rows, but no columns.

Query
Execution Time: 0 ms
Record Count: 0
Cached: No
Lazy: No

I can see this being the intended if I am returning an Array of entities where I could easily check the array length. However, for queries, I need to have a consistent result set regardless of the rows. Do I need to take a different approach on how I am filtering associated entities?

That is a ColdFusion issue itself, maybe not an issue but expected behavior. Under what circumstances do you need the columns if no rows exist?

Upon looking at the BaseORMService and how it calls entityToQuery, you’re correct on expected behavior… well, expected based on how it’s implemented, but not what I expected.

In this scenario, we’re converting an application to ORM from a DAO/gateway model. The front-end application receives a serialized representation of the query, which includes an array of data along with column names regardless of whether rows exist. This is just a standard serializeJson(qData). Upon switching to ORM and utilizing the BaseORMService.list(asQuery=true) functionality, we get identical serialized results when compared to the standard serialized query assuming results are returned. However, with no results comes no column names which does not match the behavior I would expect when serializing a query.

Looks like I will be needing to gather that information myself to return to the client.

Thanks.