2016-04-08 29 views
0

正如我在文檔中看到的:「Waterline會查看你的模型,如果它發現兩個模型都具有指向對方的集合屬性,它將自動建立起來給你一個連接表。「我的問題是如何將水線知道這表是我在where子句SAILS:如何定義關聯表mysql mysql-many

我使用MySQL作爲數據庫和我的模型看起來得到一個錯誤,現在

不明列NaN關聯表像這樣:

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數據庫2個現有的表: 種類和銷售

回答

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 
}