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?