Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询从一对多Grails域返回的格式错误的对象_Grails_Gorm - Fatal编程技术网

查询从一对多Grails域返回的格式错误的对象

查询从一对多Grails域返回的格式错误的对象,grails,gorm,Grails,Gorm,考虑这两个Grailsdomain类: class Agreement implements Serializable { String code String branchCode ... static belongsTo = [agency: CollectingAgency] static mapping = { ... } } class CollectingAgency implements Serializable

考虑这两个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
):

由于未知列(
agency\u id
),该语句将不会执行。我想知道它从哪里得到
机构id
栏?我还没有用这样的名称映射任何列

当我尝试使用
CollectingAgency.findAll()
从另一端进行查询时,它返回一个格式错误的
对象

[
    {
        type: "0400300",
        agencyClass: "12",
        ...
        agreement: [
是的,就像这样,使用
协议
键有一个方括号
[
但没有方括号
]
。另外,不会检索表的其他属性

如何使用与以下类似的结果对象实现查询:

Agreement.findAll()

CollectingAgency.findAll()


在你的协议课上你有

static belongsTo = [agency: CollectingAgency]
这将在您的类中创建一个“代理”字段。您看到的代理id只是将您的“代理”字段映射到数据库中的“代理”列

[
    {
        code: "1212",
        branchCode: "a014s",
        ...
        agency: {
            type: "0400300",
            agencyClass: "12",
            ...
        },
        ...
    },
    {
        code: "1213",
        branchCode: "a014z",
        ...
        agency: {
            type: "0400300",
            agencyClass: "12",
            ...
        },
        ...
    },
    ...
]
[
    {
        type: "0400300",
        agencyClass: "12",
        ...
        agreement: [
            {
                code: "1212",
                branchCode: "a014s",
                ...
            },
            {
                code: "1213",
                branchCode: "a014z",
                ...
            },
            ...
        ]
    },
    ...
]
static belongsTo = [agency: CollectingAgency]