最新的水线现在支持关联。这是一个一对多的例子
// 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
。
无论如何要覆盖数据库中使用的字段名称?