【发布时间】:2014-05-15 17:29:18
【问题描述】:
最新的水线现在支持关联。这是一个一对多的例子
// A user may have many pets
var User = Waterline.Collection.extend({
identity: 'user',
connection: 'local-postgresql',
attributes: {
firstName: 'string',
lastName: 'string',
// Add a reference to Pets
pets: {
collection: 'pet',
via: 'owner'
}
}
});
var Pet = Waterline.Collection.extend({
identity: 'pet',
connection: 'local-postgresql',
attributes: {
breed: 'string',
type: 'string',
name: 'string',
// Add a reference to User
owner: {
model: 'user'
}
}
});
这会在宠物集合上创建一个名为 owner 的字段。除了使用现有数据库之外,这会很好。它称之为外键owner_id。
是否有覆盖数据库中使用的字段名称?
【问题讨论】:
标签: foreign-keys associations sails.js waterline