views:

239

answers:

1

I have a many to many relationship.

class Post {
    String title
    static hasMany = [tags:Tag]
}

class Tag {
    static hasMany = [posts:Post]
}

I would like to get a list of posts for a tag that have some other criteria (like a sort order, partial title match, etc). Do I have to use the grails criteria to achieve this? Or is there some way to do something like this:

Post.findAllByTitleLikeAndTagsContains("partial title", aTag)
+2  A: 

I don't think dynamic finders will allow you to get into one to many or many to many associations - you have to do a criteria or go the HQL query route. You can only query by one to one association, not by one to many. (see section 5.4.1 Dynamic Finders)

Jean Barmash
Yep, dynamic finders only support simple properties - criteria time!
leebutts
That's what I thought. I really wish grails had an easy way to do this, but I guess I'll just have to put it in JIRA.
Blacktiger