grails - Grails-findAll连接两个表

标签 grails gorm findall

我是Grails的新手。我从数据库检索数据时遇到问题。我有带类的域名,类似...

class Lightbox {    
   String name = ''
   String link  = ''
   static hasMany = [users: LightboxUserAccount]
}

class LightboxUserAccount {
   UserAccount userAccount
   static belongsTo = [lightbox: Lightbox]  
}

class UserAccount {
   String username
   ...
}

我想列出ID = 4的用户拥有的所有“灯箱”。我在尝试
def my_lb = Lightbox.findAll("from Lightbox as lb where lb.users=:userAccount", [userAccount: springSecurityService.getCurrentUser()])

要么
def my_lb = Lightbox.findAllByUsers(4)

这些都不适合我。我究竟做错了什么?谢谢

最佳答案

试试这个:

Lightbox.findAll("from Lightbox as lb where :userAccount in (lb.users)", [userAccount: springSecurityService.getCurrentUser()])

关于grails - Grails-findAll连接两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28436190/

相关文章:

Grails 自定义验证器,获取对字段名称的引用

grails - Grails/GORM属于返回引用命名

ruby-on-rails - Grails等同于Rails ARel 'includes'

Python ElementTree findall 不起作用

grails - Bcrypt密码编码器-Grails

java - Grails Spock - 从服务抛出异常 UndeclaredThrowableException

hibernate - 使用Criteria Builder在一对多中查询另一种方式

python - findall 和正则表达式,得到正确的模式

python - beautifulsoup 网络爬虫问题 : can't find tables on webpage

grails - Grails与参数和确认链接