节点js:关联在sas js版本1中不起作用

时间:2018-04-21 18:33:14

标签: 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个模型(患者和预订),我想从预订中获得耐心

// Patients.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'
    }
}

};

1 个答案:

答案 0 :(得分:0)

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

// 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'
  }
}