gpt4 book ai didi

grails - Grails域名查询列表

转载 作者:行者123 更新时间:2023-12-02 15:05:37 25 4
gpt4 key购买 nike

我有一个简单的Grails应用程序。我有几个 Realm ,例如以下。场景是Person有很多电话(但是Person类没有将电话列表作为变量:惰性单端关联)。

class Person implements Serializable {
....
}

class Telephone implements Serializable{
String number
static belongsTo = [person : Person]
static mapping = {
.....
person lazy: false
}
}

现在,我有一个必须通过电话号码搜索此人的要求。我有一个字符串电话号码列表。我需要让所有拥有至少一个该电话号码的人。我需要编写namedQueries,但是我对这个 Realm 还很陌生。是否可以为此编写命名查询?还是我需要在Person类中定义的映射为
set telephone
static hasMany = [
telephone: Telephone
]

以及如何定义namedQueries以适合我的要求

提前致谢

最佳答案

我相信它能够看到您正确的人的电话

set telephone
static hasMany = [
telephone: Telephone
]

需要定义,但是一旦定义,您就可以执行以下操作:
 static namedQueries = {
withSameTelephone {telephoneNumber ->
telephone{ eq 'number' telephoneNumber }
}
}

并像这样使用它:
Person.withSameTelephone('091511234512').list()

我想你需要通过 list
 static namedQueries = {
withSameTelephoneInList {telephoneNumberList ->
telephone{ 'in'( 'number' telephoneNumber) }
}
}

所以你可以这样做:
Person.withSameTelephoneInList(['091511234512','091511234513','091511234514']).list()

关于grails - Grails域名查询列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33119309/

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