我在Grails中遇到GORM问题。我有两种关系,看起来像这样:
Company
static hasMany = [
users:User,
]
---------
User
// no mention about entity Company
我需要获得与某个用户相关的所有公司。
User user = springSecurityService.currentUser
def results = Company.executeQuery("select c from Company c join User u where u.id = ${user.id}")
我需要的SQL语法如下所示:Select * from Company C join User u on u.company_id=c.id where u.id=user.id.
我的错误是:Path expected for join!
在数据库中创建了一个新的连接表,它的名称为company_user
。知道怎么写这个简单的选择吗?
答案 0 :(得分:0)
这应该有效
User user = springSecurityService.currentUser
def results = Company.executeQuery(
"from Company c join c.users u where u.id = ?", [user.id])