考虑我已经构建了这样的数据库,
users:{
user1: {
username: "johndoe"
},
user2: {
username: "foobar"
}
}
user-timeline: {
user1: {
post1: true,
post2: true,
post3: true
},
user2: {
post3: true
}
}
posts: {
post1:{
caption: "caption 1",
author: "user1"
},
post2:{
caption: "caption 2",
author: "user1"
},
post3:{
caption: "caption 3",
author: "user2"
}
}
如何获取所有帖子数据的最佳方法,包括与user1的时间线相关的每个帖子的作者数据?由于user1在其时间轴中关联了post1, post2, and post3
,因此查询需要获取如下数据:
[
{
$id: post1,
caption: "caption 1",
author:{
$id: "user1", username: "johndoe"
}
},
{
$id: post2,
caption: "caption 2",
author:{
$id: "user1", username: "johndoe"
}
},
{
$id: post3,
caption: "caption 3",
author:{
$id: "user2", username: "foobar"
}
}
]
我知道,目前firebase不支持来自多个值的查询,如下所示:
$firebaseArray($firebaseRef.child('posts').equalTo(['post1','post2','post3']));
有人可以解释使用AngularFire实现它的最佳方法,并在每次添加或删除新帖子时保持数据同步吗?