【问题标题】:SAILS: How to define association table mysql many-manySAILS:如何定义关联表 mysql 多对多
【发布时间】:2016-04-10 18:53:26
【问题描述】:

正如我在文档中所读到的“Waterline 将查看您的模型,如果它发现两个模型都具有指向彼此的集合属性,它将自动为您构建一个连接表。”我的问题是水线如何知道哪个表是关联表,因为我现在遇到错误

where 子句中的未知列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
    }
  }
};

物种.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 个现有表: 品种和销售

【问题讨论】:

    标签: mysql node.js sails.js


    【解决方案1】:

    卖出:

    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
    }
    

    物种.js:

    id: {
      type: 'integer',
      primaryKey: true,
      autoIncrement: true
    },
    
    sells:{
      collection: "Sells", // match model name
      via: "Species" // match attribute name
    }
    

    【讨论】:

      猜你喜欢
      • 2014-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多