我有三张表持有这些文档:
//user----tables:users
{
Id:"user/001"
Name:"Jack Losen"
....
}
//schooling---table:schoolings
{
Id:"schooling/001"
Name:""
Major:"",
EnrollYear:1983
}
//user_schooling-----join table:user_schooling
{
user_id:"user/001"
schooling_id:"schooling/001"
}
如何将一系列学校教育作为通过联接表查询用户ID的条件:user_schooling?
例如:如果我想获得B学校一直在学校的用户的所有ID,或者(不是)在D学校的C学校...(或更多),那么我的查询条件可能是这样的:
condition: [
{
Name:"A"
....
EnrollYear:B
},
{
Name:"C"
...
EnrollYear:D
}
]
答案 0 :(得分:1)
rethinkdb邮件列表中的人给出了正确答案:
r.table('user_schooling').filter(function(row) {
return r.table('schooling').get(row('SchoolingId')).do(function(school) {
return r.expr([{Name:"MASTER", EnrollTime:2003}]).pluck('Name', '
EnrollTime').contains(school.pluck('Name', 'EnrollTime'));
});
}).pluck("UserId")