FIRDatabaseQuery: how to do an inner join

后端 未结 2 1390
有刺的猬
有刺的猬 2021-01-14 06:50

I\'m trying to do an inner join on a FIRDatabaseQuery object.

below is the database structure. I have some posts that are linked to post-comments. I am trying to get

2条回答
  •  星月不相逢
    2021-01-14 07:29

    You will need to work with nested firebase calls. You can find a javascript example in this question but your swift code should look like the following:

    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)
            }
          }
    })
    

提交回复
热议问题