Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.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
Sails.js SailsJS深度关联未填充_Sails.js - Fatal编程技术网

Sails.js SailsJS深度关联未填充

Sails.js SailsJS深度关联未填充,sails.js,Sails.js,我第一次使用SailsJS。我建立了一些有关联的模型,一切正常。差不多 以下是我的项目模型: module.exports = { attributes: { title: { type: 'string', required: true }, subtitle: { type: 'string', required: false }, image: { model: 'image' }, bgColor: { type:

我第一次使用SailsJS。我建立了一些有关联的模型,一切正常。差不多

以下是我的项目模型:

module.exports = {
    attributes: {
        title: { type: 'string', required: true },
        subtitle: { type: 'string', required: false },
        image: { model: 'image' },
        bgColor: { type: 'string', required: false },
        tabPos: { type: 'integer', required: true, defaultsTo: 0 },
        featured: { type: 'boolean', required: true, defaultsTo: false },
        contentBlocks: { collection: 'contentBlock', via: 'project' },
        position: { type: 'integer', required: true }
    }
};
下面是我的ContentBlock模型:

module.exports = {
    attributes: {
        project: { model: 'project' },
        copy: { type: 'string', required: true },
        icon: { type: 'integer', required: false },
        images: { collection: 'image' },
        bgColor: { type: 'string', required: false },
        position: { type: 'integer', required: true }
    }
};
最后,我的图像模型:

module.exports = {
    attributes: {
        filename: { type: 'string', required: true },
        alt: { type: 'string', required: true },
        device: { type: 'string', required: true, defaultsTo: 'laptop' },
        deviceColor: { type: 'string', required: false }
    }
};
所有的关联都很有效,除了项目端点没有在有效负载中包含contentBlock图像。它甚至不包含ID数组。它只是完全忽略该属性:

[
    {
        contentBlocks: [
            {
                project: "5406ffb56d109ad149a14362",
                copy: "Lorum ipsum",

                // expecting array of image ids here
                // but its completely missing

                position: 0,
                createdAt: "2014-09-03T11:49:08.162Z",
                updatedAt: "2014-09-03T12:13:55.279Z",
                id: "540700346d109ad149a14363"
            }
        ],
        image: {
            filename: "test1_320x480.jpg",
            alt: "A test image",
            device: "laptop",
            createdAt: "2014-09-03T11:36:13.608Z",
            updatedAt: "2014-09-03T11:36:13.608Z",
            id: "5406fd2d6d109ad149a1435e"
        },
        title: "Project Alpha",
        subtitle: "A test project",
        position: 0,
        tabPos: 0,
        featured: false,
        createdAt: "2014-09-03T11:47:01.155Z",
        updatedAt: "2014-09-03T12:13:35.972Z",
        id: "5406ffb56d109ad149a14362"
    }
]
但是,contentBlock端点不包括图像

[
    {
        images: [
            {
                filename: "test2_320x480.jpg",
                alt: "Another test image",
                device: "ipad",
                deviceColor: "#FFF",
                createdAt: "2014-09-03T11:36:50.875Z",
                updatedAt: "2014-09-03T11:39:38.216Z",
                id: "5406fd526d109ad149a1435f"
            },
            {
                filename: "test3_320x480.jpg",
                alt: "The last test image",
                device: "iphone",
                deviceColor: "#000",
                createdAt: "2014-09-03T11:43:09.599Z",
                updatedAt: "2014-09-03T11:43:09.599Z",
                id: "5406fecd6d109ad149a14361"
            }
        ],
        project: {
            title: "Project Alpha",
            subtitle: "A test project",
            image: "5406fd2d6d109ad149a1435e", // sails is populating this association fine
            position: 0,
            tabPos: 0,
            featured: false,
            createdAt: "2014-09-03T11:47:01.155Z",
            updatedAt: "2014-09-03T12:13:35.972Z",
            id: "5406ffb56d109ad149a14362"
        },
        copy: "Lorum ipsum",
        position: 0,
        createdAt: "2014-09-03T11:49:08.162Z",
        updatedAt: "2014-09-03T12:13:55.279Z",
        id: "540700346d109ad149a14363"
    }
]
在这个阶段,我只覆盖了模型,其他的都是默认的


非常感谢您的帮助。

可能是@sgress454的副本我看了那篇文章,虽然这篇文章把我放在了正确的位置,但我仍然面临同样的问题,即字符串化结果对象:。我最终决定使用sails ember蓝图: