TypeError:Object[Object Array]没有方法';getProperty';


TypeError: Object [object Array] has no method 'getProperty'

我对这整个发布问题的事情有点陌生,所以请温柔一点!

我使用Breeze作为"Hot Towel"SPA堆栈的一部分,并从用PHP编写的自定义WebApi端点检索数据。这不是一个完整的实现,我只是写了足够的东西来满足我的需求。

我的端点正在生成的元数据如下:

 {
        "shortName": "Project",
        "namespace": "WebApi.ORM.Cartesius",
        "autoGeneratedKeyType": "Identity",
        "defaultResourceName": "Project",
        "dataProperties": [
            {
                "name": "id",
                "isPartOfKey": true,
                "isNullable": false,
                "dataType": "Int32"
            },
            {
                "name": "title",
                "isNullable": false,
                "maxLength": 256,
                "dataType": "String"
            },
            {
                "name": "date",
                "isNullable": false,
                "dataType": "DateTime"
            },
            {
                "name": "review_date",
                "isNullable": true,
                "dataType": "DateTime"
            },
            {
                "name": "summary",
                "isNullable": true,
                "dataType": "String"
            }
        ],
        "navigationProperties": [
            {
                "name": "Team",
                "entityTypeName": "Team:#WebApi.ORM.Cartesius",
                "isScalar": true,
                "associationName": "team_project_id_fkey",
                "invForeignKeyNames": [
                    "project_id"
                ]
            },
            {
                "name": "ProjectAuthor",
                "entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
                "isScalar": true,
                "associationName": "project_author_project_id_fkey",
                "invForeignKeyNames": [
                    "project_id"
                ]
            },
            {
                "name": "Itinerary",
                "entityTypeName": "Itinerary:#WebApi.ORM.Cartesius",
                "isScalar": true,
                "associationName": "itinerary_project_id_fkey",
                "invForeignKeyNames": [
                    "project_id"
                ]
            },

一切都很好,直到我尝试对我的查询进行扩展:

var query = new breeze.EntityQuery()
        .from("Project")
        .where("id","eq",project.id)
        .expand("ProjectAuthor");

此查询从我的端点返回以下内容:

[
{
    "$id": 1,
    "$type": "WebApi.ORM.Cartesius.Project",
    "id": 2,
    "title": "teat",
    "date": "2013-11-04 14:00:00+07",
    "review_date": null,
    "summary": null,
    "ProjectAuthor": [
        {
            "$id": 2,
            "$type": "WebApi.ORM.Cartesius.ProjectAuthor",
            "id": 1,
            "account_id": 1,
            "project_id": 2,
            "Project": [
                {
                    "$ref": 1
                }
            ]
        },
        {
            "$id": 3,
            "$type": "WebApi.ORM.Cartesius.ProjectAuthor",
            "id": 3,
            "account_id": 2,
            "project_id": 2,
            "Project": [
                {
                    "$ref": 1
                }
            ]
        }
    ]
}

]

然后Breeze在投掷时窒息:

TypeError: Object [object Array] has no method 'getProperty'

调试指向Breeze中的第5059行,它试图在一个实体数组而不是单个实体上获取属性。我认为这与导航属性是否设置为标量有关,但切换它们并没有什么区别。

我确信我做错了什么,但我不知道是什么,我有点碰壁了。我已经从上到下阅读了文档,并尽我所能实现了这一点,但可能我有点困惑。

提前感谢您的帮助,如果我没有明确表示或提供足够的信息

我认为您的问题在于元数据

     "name": "ProjectAuthor",
            "entityTypeName": "ProjectAuthor:#WebApi.ORM.Cartesius",
            "isScalar": true,
            "associationName": "project_author_project_id_fkey",
            "invForeignKeyNames": [
                "project_id"
            ]
        },

在导航属性Project->ProjectAuthor上,您告诉它它是一个标量,但它不在数据集中。。"项目作者":[{……….

我也遇到过这个问题。。99%的时间都是元数据问题,如果没有,那么就开始分割元数据,直到隔离错误。。尽管我确信这就是问题所在。。你需要一个hasMany和一个isScalar在反向导航上