gpt4 book ai didi

grails - Grails-findAll连接两个表

转载 作者:行者123 更新时间:2023-12-02 16:02:51 24 4
gpt4 key购买 nike

我是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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com