I have the following Grails domain objects
class ProductType {
String name
static hasMany = [attributes: Attribute]
}
class Attribute {
Boolean mandatory = false
Integer seq
static belongsTo = [productType: ProductType]
}
I would like to get all ProductTypes and their mandatory Attributes. Furthermore, I’d like the selected Attributes to be eagerly loaded and sorted by the seq property. I’ve tried all kinds of HQL and Criteria queries, but can’t seem to figure it out.
This query will return all ProductTypes that have mandatory attributes, with those attributes eagerly loaded:
The attributes are in mapped Sets, so there’s no ordering, but it’s easy enough to collect and sort them: