FIRDatabaseQuery: how to do an inner join

后端 未结 2 1380
有刺的猬
有刺的猬 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:16

    You may want to consider

    "posts" : {
        "-KIycKhZU55dmKnHbbxv" : {
          "author" : "John Doe",
          "body" : "This is a post test",
          "title" : "test",
          "uid" : "SHaH36BLwgPvwgi9cDmRnsnONFB2"
          "commented_by"
               "SHaH36BLwgPvwgi9cDmRnsnONFB2": true
    

    Then you can simply query for

    posts.child("commented_by/uid").queryEqualToValue(true)
    

    or, change the post-comments around to better match the queries you want to do:

    "post-comments" : {
      "-KIycMyL0Vy1BHVdI4zc" : {
         "author" : "toto",
         "post_data":
              post_id: "-KIycKhZU55dmKnHbbxv",
              post_title: "test"
         "text" : "test",
         "uid" : "SHaH36BLwgPvwgi9cDmRnsnONFB2"
    },
    

    That makes the query a snap as the post-comments node can be queried for the uid which return all of the post_id's of the posts they commented on. It wouldn't return the post itself, however, you may just be looking for the title so you can populate a list. Once the user taps it clicks it you can retrieve the actual data.

提交回复
热议问题