[英]Malformed object returned by query from a one-to-many Grails domain
考慮以下兩個Grails domain
類:
class Agreement implements Serializable {
String code
String branchCode
...
static belongsTo = [agency: CollectingAgency]
static mapping = {
...
}
}
class CollectingAgency implements Serializable {
String type
String agencyClass
...
static hasMany = [agreement: Agreement]
static mapping = {
...
}
}
現在,當我執行Agreement.findAll()
它會創建一個與此類似的sql(使用loggingSql = true
):
select agreement0_.agency_id as agency4_67_1_, agreement0_.AGREH_CD as
AGREH1_1_, agreement0_.AGREH_BRCHCD as AGREH2_1_,
...
agreement0_.agency_id as agency4_66_0_,
^^^^^^^^^
...
from RVAGREHDROTB agreement0_
where agreement0_.agency_id=?
由於未知列( agency_id
),該語句將不會執行。 而且我想知道它從哪里獲得agency_id
列? 我還沒有映射任何具有這種名稱的列。
當我嘗試使用CollectingAgency.findAll()
從另一端查詢時,它返回格式錯誤的Object
:
[
{
type: "0400300",
agencyClass: "12",
...
agreement: [
是的,這樣, agreement
密鑰具有方括號[
但沒有方括號]
。 此外,不會檢索表的其他屬性。
如何使用與以下結果類似的對象實現查詢:
Agreement.findAll()
:
[
{
code: "1212",
branchCode: "a014s",
...
agency: {
type: "0400300",
agencyClass: "12",
...
},
...
},
{
code: "1213",
branchCode: "a014z",
...
agency: {
type: "0400300",
agencyClass: "12",
...
},
...
},
...
]
和CollectingAgency.findAll()
:
[
{
type: "0400300",
agencyClass: "12",
...
agreement: [
{
code: "1212",
branchCode: "a014s",
...
},
{
code: "1213",
branchCode: "a014z",
...
},
...
]
},
...
]
在您的協議課程中
static belongsTo = [agency: CollectingAgency]
這將在您的班級中創建一個“代理商”字段。 您看到的agency_id只是將您的“代理商”字段映射到數據庫中的“代理商”列。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.