mysql - Node js : association not working in sails js version 1

标签 mysql node.js sails.js associations one-to-one

请帮助我,我正在使用 Sails 版本 1,我想创建关联,但出现错误。

error: A hook (`orm`) failed to load!
error: Could not tear down the ORM hook.  Error details: Error: Invalid data store identity. No data store exist with that identity.
error: Failed to lift app: { userError: The attribute `id` on the `patients` model is an association but also specifies a type property. This is not needed and will be automatically determined.

所以我有一个 2 模型(患者和预订),我想从预订中获得患者

//Patents.js

module.exports = {
tableName: 'patients',
primaryKey: 'id',
attributes: {
    id: {
        model: 'Bookings',
        type: 'number',
        unique: true
    }
},

};

//Bookings.js

module.exports = {
tableName: 'booking',
attributes: {
    patient: {
        collection: 'Patients',
        via: 'id'
    }
}

};

最佳答案

按照错误提示,从 Patients.js 中的 attributes 键中删除 type 属性。

// Patients
module.exports = {
tableName: 'patients',
primaryKey: 'id',
attributes: {
 id: {
    type: 'number',
    unique: true
    },
 RandomAssociationName: {
    model: 'Bookings'
    }
}

// Bookings
module.exports = {
tableName: 'booking',
attributes: {
patient: {
    collection: 'Patients',
    via: 'RandomAssociationName'
  }
}

关于mysql - Node js : association not working in sails js version 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49959007/

相关文章:

mysql - 在 MySQL 数据库中实现复杂的约束

mysql - 如何根据一个或多个结果集中的列删除重复项

node.js - 如何将Node中发生的错误传达给Web用户?

node.js - 在 gcloud 上调试 Node 应用程序以修复 500 服务器错误

mysql - 列选项卡中未显示的列 (MySQL Workbench)

Node.js module.exports 函数从 MongoDB 返回数组

javascript - 发送2个数组以在sails js中查看

javascript - 在 Sails 中使用多个 unirest 请求

sails.js - 如何从 SailsJS 中的 Actions2 函数访问 req 对象?

php - Mysql数据库警告