gpt4 book ai didi

sails.js - 水线,尝试创建一对多关联时出错

转载 作者:行者123 更新时间:2023-12-04 15:57:37 27 4
gpt4 key购买 nike

我有这些模型:

// Material.js

module.exports = {
attributes: {

name: {
type: 'string',
required: true
},
source_info: {
type: 'string',
required: true
},
category: { model: 'category_mat' }
}
};

和:
// Category_Mat.js

module.exports = {
attributes: {
name: {
type: 'string',
required: true
},
material:{
collection: 'material',
via: 'category'
}
},
};

但是当我运行该应用程序时,我收到此错误:
/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82
throw new Error('Trying to access a collection ' + collection + ' that is
^

Error: Trying to access a collection category_mat that is not defined.

at ForeignKeys.findPrimaryKey (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:82:11)
at ForeignKeys.replaceKeys (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:53:27)
at new ForeignKeys (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema/foreignKeys.js:30:10)
at new module.exports (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/waterline-schema/lib/waterline-schema.js:30:17)
at Waterline.initialize (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline.js:106:17)
at buildORM (/usr/local/lib/node_modules/sails/lib/hooks/orm/build-orm.js:48:15)
at Array.async.auto.instantiatedCollections [as 1] (/usr/local/lib/node_modules/sails/lib/hooks/orm/index.js:191:11)
at listener (/usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:465:46)
at /usr/local/lib/node_modules/sails/node_modules/async/lib/async.js:419:17
at Array.forEach (native)

我使用此文档作为引用:
http://sailsjs.org/#/documentation/concepts/ORM/Associations/OnetoMany.html

所以我不知道我错过了什么,或者是否有我必须做的配置......有什么帮助吗?

最佳答案

也许是因为 Material.js 上使用的“category-mat”没有在任何地方定义......试试

// Category_Mat.js

module.exports = {
identity: 'category_mat',
attributes: {
name: {
type: 'string',
required: true
},
material:{
collection: 'material',
via: 'category'
}
},
};

如果这有效,唯一的副作用是即使您将 config/globals.js/models 设置为“true”,您也无法使用“Category_Mat”访问 Controller 中的模型。您将不得不使用“sails.models.category_mat”或仅使用“category_mat”。

关于sails.js - 水线,尝试创建一对多关联时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25277538/

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