ReactiveDB/core

Association query

Brooooooklyn opened this issue · 5 comments

Transform

{
  _id: 'pseudo_xxxx',
  creatorId: '123456'
  creator: {
    id: '123456'
    name: 'xxx',
    gender: 'male'
  }
}

to

SELECT 
  _id,
  Member.id,
  Member.name,
  Member.gender
FROM Message 
JOIN Member ON Message.creatorId = Member.id
WHERE Member.gender = 'male'

我发现这里可能会牵涉到一个self-join的二义性 - -

SELECT 
  _ID,
  Member.id,
  Member.name
FROM Member
JOIN Member AS M2 ON Member.manager = M2.name
WHERE M2.name = 'hahaha' 

由于reactivedb里 AS 这个步骤是我们自己指定的,外部无法直接具名,所以 association query 可能需要添加在这里

  fields: ['_id', 'name', 'content', {
    project: ['_id', 'name'],
    executor: ['_id', 'name', 'avatarUrl']
  }]

from https://github.com/ReactiveDB/core/blob/master/docs/API-description/QueryDescription.md

或者为QueryDescription新加一个字段叫associationClause (随便起的) ?

讲道理,那个子句约束,应该算在 joinInfo的一部分

约束放在 joinInfo 里面实现起来是最方便的,但是接口可能就没法很好看了。
我想实现成 Nested Key 这样:

{
  'member.age': {
    $gt: 10
  }
}

容我想想看看这样能不能自动 match 上 alias 过的 join table吗

好像是可以的,match 对象 virtual referrence 的 key 就好了