sailsjs:我正在尝试定义一个模型。我想添加一个属性vendorID。类型将是vendor集合中的monogdb objectID。
像商店模型的东西:
module.exports ={
attributes :{
vendorId : { type: <Monog ObjectId>}, <-- this would be a FK to the vendor Collection
storeName: {type: 'string'}
....
}
水线文件说:
目前提供以下属性类型:
那我该选哪个?
由于
答案 0 :(得分:4)
您应该查看SailsJS associations。使用水线,您不需要直接处理id
类型。只需通过model
或collection
属性创建指向其他集合的属性。
这是Sails / Waterline文档中的一个简单示例。
//Pet.js - A Pet may only have a single user
module.exports = {
attributes: {
name:'STRING',
color:'STRING',
owner:{
model:'user'
}
}
}
//User.js - A user may have multiple pets
module.exports = {
attributes: {
name:'STRING',
age:'INTEGER',
pets:{
collection: 'pet',
via: 'owner'
}
}
}
答案 1 :(得分:0)
水线为您自动创建_id,您无需这样做。