我有一个关于节点 orm2 hasMany 关联的问题,我的模型定义是这样的。
架构/Channel.js
var model = db.define('channels', Channel, ChannelOptions);
var Channel = {
channel_name : String,
channel_email : String,
channel_id : String,
views : Number
};
var ChannelOptions = {
id : "channel_id",
methods: {
my_details : function (err) {
return this.channel_id +' '+ this.channel_name + ' ' + this.views;
}
}
};
架构/network.js
var model = db.define('networks', Network, NetworkOptions);
var Channel = require('../schemas/Channel')(db);
model.hasMany('channels', Channel, {}, {autoFetch:true});
model.sync()
db.sync(function(){
console.log('DB SYNCHED');
});
var Network = {
network_id : Number,
name : String,
username : String,
logo : String,
website : String
};
var NetworkOptions = {
id : "network_id",
methods: {
}
};
它创建了一个networks_channels 表,我用networkID 和channelID 填充了它。它正在响应属性(通道),但它是空的。有什么遗漏吗?