开发者

Grails: How to combine findAllBy and findAllByTag

开发者 https://www.devze.com 2022-12-11 11:28 出处:网络
as I am new to Grails and dynamic languages, I do have some \'hopefully simple\' question. I installed the taggable plugin which works fine. There is an array coming in with tags. I collect for ever

as I am new to Grails and dynamic languages, I do have some 'hopefully simple' question.

I installed the taggable plugin which works fine. There is an array coming in with tags. I collect for every tag the set of data with findAllByTag. After that I randomise it and pick one entry. Works great. Now I decided not to take all objects from the DB. I only need all with a certain creteria(DB column customerID). This would look like this:

def customerSet = Customer.findAllBycustomerID(params.customerID)

I got both querys working, but can not combine as I want. I tried something like

def hits = customerSet.findAllByTag(tag)

But then I get a

groovy.lang.MissingMethodException: No signature of method: java.util.开发者_高级运维ArrayList.findAllByTag() is applicable for argument types: (java.lang.String) values: [mac]

I guess I can not do a findAllByTag on a list like that.

Or do I have to do it somehow like this:

def customerSet = Customer.findAllBycustomerID(params.customerID.findAllByTag(tag)) ???

thanks, klaas


I'm not sure if this works with taggable but you can use a dynamic finder with two properties e.g. .findAllByCustomerIdAndTag(customerId,tag)

If that doesn't work, you can use a criteria e.g.

Customer.createCriteria().list{
    eq('customerId',someCustomerId)
    tags{
        eq('name',someTag')
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消