I have an entity that has multiple fields; one of the fields is "quantifications", which holds a collection of different entities.
I'm querying for this entity in an API controller call that returns a list via JSON. I want to filter the result set I'm returning by the following criteria:
- If the "quantifications" field is empty, don't return that entity as part of the result.
- If the "quantifications" field is not empty, only return entities where all Quantification entities in the collection have a status of "approved".
Coldfusion isn't a language I'm terribly familiar with. I have the following code that meets the first criterion:
var EventCriteria = EventService.newCriteria();
EventCriteria.isNotEmpty('quantifications');
How can I check for the second criteria? Thank you.
Edit: Okay, I've been trying a few things, and I'm running into "method not found" errors. Posting the code below.
if (NOT showEventsWithoutQuantifications){
EventCriteria.isNotEmpty('quantifications');
var eventStatus = eventStatusService.findWhere(entityName="EventStatus", criteria={eventStatusOrder=javaCast( "int", 150 )}); //approved
// According to the Coldbox documentation, this should have worked. It doesn't.
// var QuantificationService = quantificationService.newCriteria()
// .isEq("Quantification.status", eventStatus)
// .withProjections(property="event.eventID");
// EventCriteria.in("eventID", QuantificationService); // .in() method not found. Why?
// EventCriteria.add(EventCriteria.restrictions.in("eventID", QuantificationService)); // .in() method not found. Why?
EventCriteria.add(wmtEventCriteria.createSubcriteria('Quantifications').isEq("status", eventStatus)); // .createSubcriteria method () method not found. Why?
}
For what it's worth, the EventService
inherits from coldbox.system.orm.hibernate.VirtualEntityService
. I haven't found the code for that class yet (as I'm not using a native CF IDE for this) but I would imagine that this should expose the methods in question...?
Could this be an issue with the Hibernate version I'm running against? Or perhaps the version of Coldbox?