如果切换到v0.10分支,可以尝试以下方法,
// Users.js
module.exports = {
tableName: 'user',
attributes: {
email: 'STRING',
password: 'STRING',
}
items: {
collection: 'item',
via: 'users',
through: 'useritem'
}
}
// Items.js
module.exports = {
tableName:'item',
attributes: {
name: 'STRING'
}
users: {
collection: 'user',
via: 'items',
through: 'useritem'
}
}
// Groups.js
module.exports = {
tableName: 'group',
tables: ['user', 'item'],
junctionTable: true,
attributes: {
id: {
primaryKey: true,
autoIncrement: true,
type: 'integer'
},
user_items: {
columnName: 'user_items',
type: 'integer',
foreignKey: true,
references: 'user',
on: 'id',
via: 'item_users',
groupBy: 'user'
},
item_users: {
columnName: 'item_users',
type: 'integer',
foreignKey: true,
references: 'item',
on: 'id',
via: 'user_items',
groupBy: 'item'
}
}
}
Run Code Online (Sandbox Code Playgroud)
我必须通过这个文件中的代码来了解发生了什么.
从 Sails.js v0.9.4 开始,该框架尚不支持关联。
Balderdash(Sails 的开发者)表示关联和交易都在生产版本的路线图上,并在GitHub 上的#124 问题中记录了可能的 API
目前 Waterline(Sails 使用的 ORM 适配器)有一个支持关联的开发分支,但是在查找有关新 API 的文档时可能会遇到一些问题
目前,您必须发挥创造力并寻找连接用户和项目的替代方法
| 归档时间: |
|
| 查看次数: |
4665 次 |
| 最近记录: |