gorm - Grails Criteria multiple hasMany intersection -
i've been trying query multiple hasmany objects, such as:
def product = product.createcriteria().list { createalias("productattributevalues", "pav") , { if (session.filters?.filter_instore) { , { eq("pav.attribute", attribute.findbycode("instore")) eq("pav.valuede", session.filters?.filter_instore?.tostring()) } } if (session.filters?.filter_promo) { , { eq("pav.attribute", attribute.findbycode("promo")) eq("pav.valuede", "1") } } } }
this doesn't seem work, since never result set, although have test data match. seems problem i'm querying twice same objects.
one possible solution query productattributevalues seperately , intersect "in"("mypavs", pavs) - seems inefficient me.
any thoughts? thanks.
i re-build query so:
def products = product.withcriteria{ productattributevalues{ or{ if (session.filters?.filter_instore) { , { eq("attribute", attribute.findbycode("instore")) eq("valuede", session.filters?.filter_instore?.tostring()) } } if (session.filters?.filter_promo) { , { eq("attribute", attribute.findbycode("promo")) eq("valuede", "1") } } } } }
Comments
Post a Comment