应该知道我的意思吧,比如

User

{
  id: 'userId',
  name: 'name',
  age: 'age'
}

Post

{
  userId: 'userId',
  title: 'title',
  content: 'content'
}

之前用 MongoDB 的时候,查询 Post 直接指定 .populate('userId') 就最终就可以得到

{
  userId: {
    id: 'userId',
    name: 'name',
    age: 'age'
  },
  title: 'title',
  content: 'content'
}

但是用了你们的产品后,发现不是很方便了,你们提供了关系相关 API 但是看文档例子我感觉好像不是我理解的样子

一对一关系里,你们把 post 关联到 commend 里,然后并没有说明如何在获取 commend 的时候同时获取到完整的 post 对象内容,只给了个不明不白的例子:

var post = fetchedComment.get('post');
post.fetch({
  // 用法可参考 API 文档 > AV.Object > fetch
  include: 'author'
}).then(function(post) {
  // 成功
  var content = post.get('content');
}, function(error) {
  // 失败
});

这个例子里,我可以理解为 fetchedComment 是通过某种 query 查到了,然后通过 fetchedComment.get 来获取 post 里的 author 属性?

可否做到获取 fetchedComment 的同时 post 所有需要的属性?就跟 population 机制差不多

谢谢

抱歉,文档没有写清楚给你造成了困惑,根据你前面的场景,在查询 Post 的时候加上 include: userId 即可:

var query = new AV.Query('Post');
query.include('userId').find().then(function(posts) {
    // posts 中每个 post 的 userId 属性都是一个完整的 User 对象,就像你前面所希望得到的。
}, console.error);