我正在尝试在FIR DatabaseQuery对象上进行内部联接. 下面是数据库结构.我有一些链接到评论后的帖子.我试图获取特定用户添加评论的所有帖子: { "posts" : { "-KIycKhZU55dmKnHbbxv" : { "author" : "
下面是数据库结构.我有一些链接到评论后的帖子.我试图获取特定用户添加评论的所有帖子:
{ "posts" : { "-KIycKhZU55dmKnHbbxv" : { "author" : "John Doe", "body" : "This is a post test", "title" : "test", "uid" : "SHaH36BLwgPvwgi9cDmRnsnONFB2" }, "-KIyg_ks1O5QL4_4dfq_" : { "author" : "Jane Doe", "body" : "This is a post test", "title" : "test2", "uid" : "x5leSBGArnd10JilD9YDyNBNfZ03" },... } "post-comments" : { "-KIycKhZU55dmKnHbbxv" : { "-KIycMyL0Vy1BHVdI4zc" : { "author" : "toto", "text" : "test", "uid" : "SHaH36BLwgPvwgi9cDmRnsnONFB2" }, "-KIyg_ks1O5QL4_4dfq_" : { "author" : "toto", "text" : "test", "uid" : "SHaH36BLwgPvwgi9cDmRnsnONFB2" } },... }
在SQL中,这将被翻译成类似于的内部联接查询:
选择*来自post post的内部联接后评论post-comments.uid =“user id”
有人知道如何在firebase中获得类似于内连接的东西吗?
非常感谢,
亚辛
ref.child("posts").observeEventType(.ChildAdded, withBlock: { (snapshot) in if let postId = snapshot.key as! String { let commentsRef = ref.child("post-comments") commentsRef.child(postId).queryOrderedByChild("uid").queryEqualToValue(userId).observeSingleEventOfType(.Value, withBlock: { (snapshot) in for child in snapshot.children.allObjects as [FDataSnapshot] { print(child.value) } }) { (error) in print(error.localizedDescription) } } })