SAILS:如何定义关联表mysql很多

时间:2016-04-08 05:08:46

标签: mysql node.js sails.js

正如我在文档中所读到的那样,“Waterline会查看你的模型,如果它发现两个模型都有相互指向的集合属性,它会自动为你建立一个连接表。”我的问题是水线如何知道哪个表是关联表,因为我现在收到错误

  where子句

中的

unknow列NaN

我使用MYSQL作为数据库,我的模型看起来像这样:

Sells.js:

module.exports = {
  autoCreatedAt: true,
  autoUpdatedAt: false,
  attributes: {
    createdAt:{
        type:'datetime',
        columnName:'created'
    },
    qty_sold:{
        type:'float'
    },
    s_notes:{
        type:'string'
    },
    items: {
      collection: 'species',
      via: 'sales',
      dominant:true
    }
  }
};

Species.js:

    module.exports = {
  autoCreatedAt: false,
  autoUpdatedAt: false,
  attributes: {
    name:{
        type:'string',      
    },
    qty:{
        type:'float',   
    },
    sort:{
        type:'float',
    },
    quickbooks_listid:{
        type:'string'   
    },
    quickbooks_editsequence:{
        type:'string'   
    },
    isEdited:{
        type:'integer'
    },
    cut_fish:{
        type:'integer'
    },
    // Add a reference to Sells
    sales: {
      collection: 'sells',
      via: 'items',
      //dominant: true
    }
  }

};

我在mysql DB中有2个现有表: 物种和销售

1 个答案:

答案 0 :(得分:0)

卖:

id: {
  type: 'integer',
  primaryKey: true,
  autoIncrement: true
},

species:{
  collection: "species", // match model name here
  via: "Sells", // match attribute name on other model
  dominant: true // dominant side
}

Species.js:

id: {
  type: 'integer',
  primaryKey: true,
  autoIncrement: true
},

sells:{
  collection: "Sells", // match model name
  via: "Species" // match attribute name
}