【发布时间】:2014-12-29 00:43:10
【问题描述】:
你好,
在采用 hacky/cutom 方式之前,我想知道是否有内置的 query 方法来检查空/非空多对多关系,因为我在 google 和 doc 上都没有成功。
如果我以文档中的示例为例,假设我只想在用户拥有宠物时检索用户,或者通过查询检索没有任何所有者的宠物。
// 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 Pet
pets: {
collection: 'pet',
via: 'owners',
dominant: true
}
}
});
// A pet may have many owners
var Pet = Waterline.Collection.extend({
identity: 'pet',
connection: 'local-postgresql',
attributes: {
breed: 'string',
type: 'string',
name: 'string',
// Add a reference to User
owners: {
collection: 'user',
via: 'pets'
}
}
});
附:我知道如何在查询执行后过滤结果,这不是我要问的:)
【问题讨论】: