Note that there are some explanatory texts on larger screens.

plurals
  1. POColdfusion Hibernate - Filter results by field value inside collection
    primarykey
    data
    text
    <p>I have an entity that has multiple fields; one of the fields is "quantifications", which holds a collection of different entities.</p> <p>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:</p> <ol> <li>If the "quantifications" field is empty, don't return that entity as part of the result.</li> <li>If the "quantifications" field is not empty, only return entities where all Quantification entities in the collection have a status of "approved".</li> </ol> <p>Coldfusion isn't a language I'm terribly familiar with. I have the following code that meets the first criterion:</p> <pre><code>var EventCriteria = EventService.newCriteria(); EventCriteria.isNotEmpty('quantifications'); </code></pre> <p>How can I check for the second criteria? Thank you.</p> <p><strong>Edit:</strong> Okay, I've been trying a few things, and I'm running into <em>"method not found"</em> errors. Posting the code below.</p> <pre><code>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? } </code></pre> <p>For what it's worth, the <code>EventService</code> inherits from <code>coldbox.system.orm.hibernate.VirtualEntityService</code>. 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...?</p> <p>Could this be an issue with the Hibernate version I'm running against? Or perhaps the version of Coldbox?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload