gorm one to many search

时光毁灭记忆、已成空白 提交于 2019-12-22 11:37:14

问题


Have the following problem: I have Bookmaker and Users domain classes. And one Bookmaker has many Users.

class Bookmaker {
    ...
    static hasMany = [users: User ...]
    ...
}

And User domain class doesn't contain reference to Bookmaker. My goal is to create method that will return Bookmaker that owns particular User. It looks like:

def lookupBookmaker() {
    User user = User.get(springSecurityService.principal.id)
    def query = Bookmaker.where {
        users.contains(user)
    }
    Bookmaker bookmaker = query.find()
    bookmaker
}

but it doesn't work and gives the following exception:

Class groovy.lang.MissingMethodException Message No signature of method: grails.gorm.DetachedCriteria.contains() is applicable for argument types: (cmscore.User) values: [cmscore.User : 2] Possible solutions: toString(), toString(), notify(), combinations()

and it says that wrong code is this:

users.contains(user)

What I'm doing wrong? Thanks!

来源:https://stackoverflow.com/questions/25309013/gorm-one-to-many-search

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!