How do I structure a firebase database for this case?











up vote
0
down vote

favorite












Basically I would like to display every tobacco and all the available hookahs in a UITableView, based on if the tobacco segment or the hookah segment is pressed. First you should see the brand and after that the "products" (like all tobaccos or hookahs).
So now, how exactly should the firebase database then look like? Because every product (hookah, tobacco) should have a "name", "brand", "rating" and "description".
The second question: How would I receive all these informations in my tableview by code? For now I am working with the following structure of sections for my tableview which is dependent on the var p if it is 0 or 1. Then it selects the section on index 0 or 1 (based on which segment is clicked).



var sections = [[Section(brand: "7 Days", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false),
Section(brand: "Zomo", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false)],
[Section(brand: "Aeon", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false),
Section(brand: "Vendetta", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false)]]


What the tableView looks like when its expanded



I would really appreciate any answer to any of the two problems.
Thank you!










share|improve this question
























  • This isn't a code writing service but we will be happy to help you with existing code you're having difficulty with. If you are asking how to Read Data from Firebase, it's pretty well covered in the documentation. To do your structure 'right' we would need more information. i.e. are you going to query your child nodes? If so, what for? How your data is structured is directly related to what you want to get out of it. Write some code and update your question when you get stuck.
    – Jay
    Nov 25 at 13:27

















up vote
0
down vote

favorite












Basically I would like to display every tobacco and all the available hookahs in a UITableView, based on if the tobacco segment or the hookah segment is pressed. First you should see the brand and after that the "products" (like all tobaccos or hookahs).
So now, how exactly should the firebase database then look like? Because every product (hookah, tobacco) should have a "name", "brand", "rating" and "description".
The second question: How would I receive all these informations in my tableview by code? For now I am working with the following structure of sections for my tableview which is dependent on the var p if it is 0 or 1. Then it selects the section on index 0 or 1 (based on which segment is clicked).



var sections = [[Section(brand: "7 Days", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false),
Section(brand: "Zomo", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false)],
[Section(brand: "Aeon", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false),
Section(brand: "Vendetta", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false)]]


What the tableView looks like when its expanded



I would really appreciate any answer to any of the two problems.
Thank you!










share|improve this question
























  • This isn't a code writing service but we will be happy to help you with existing code you're having difficulty with. If you are asking how to Read Data from Firebase, it's pretty well covered in the documentation. To do your structure 'right' we would need more information. i.e. are you going to query your child nodes? If so, what for? How your data is structured is directly related to what you want to get out of it. Write some code and update your question when you get stuck.
    – Jay
    Nov 25 at 13:27















up vote
0
down vote

favorite









up vote
0
down vote

favorite











Basically I would like to display every tobacco and all the available hookahs in a UITableView, based on if the tobacco segment or the hookah segment is pressed. First you should see the brand and after that the "products" (like all tobaccos or hookahs).
So now, how exactly should the firebase database then look like? Because every product (hookah, tobacco) should have a "name", "brand", "rating" and "description".
The second question: How would I receive all these informations in my tableview by code? For now I am working with the following structure of sections for my tableview which is dependent on the var p if it is 0 or 1. Then it selects the section on index 0 or 1 (based on which segment is clicked).



var sections = [[Section(brand: "7 Days", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false),
Section(brand: "Zomo", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false)],
[Section(brand: "Aeon", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false),
Section(brand: "Vendetta", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false)]]


What the tableView looks like when its expanded



I would really appreciate any answer to any of the two problems.
Thank you!










share|improve this question















Basically I would like to display every tobacco and all the available hookahs in a UITableView, based on if the tobacco segment or the hookah segment is pressed. First you should see the brand and after that the "products" (like all tobaccos or hookahs).
So now, how exactly should the firebase database then look like? Because every product (hookah, tobacco) should have a "name", "brand", "rating" and "description".
The second question: How would I receive all these informations in my tableview by code? For now I am working with the following structure of sections for my tableview which is dependent on the var p if it is 0 or 1. Then it selects the section on index 0 or 1 (based on which segment is clicked).



var sections = [[Section(brand: "7 Days", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false),
Section(brand: "Zomo", products: ["Tabak1", "Tabak2", "Tabak3"], expanded: false)],
[Section(brand: "Aeon", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false),
Section(brand: "Vendetta", products: ["Shisha1", "Shisha2", "Shisha3"], expanded: false)]]


What the tableView looks like when its expanded



I would really appreciate any answer to any of the two problems.
Thank you!







swift firebase






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 17:18









rmaddy

237k27308374




237k27308374










asked Nov 22 at 16:26









F. Leeser

34




34












  • This isn't a code writing service but we will be happy to help you with existing code you're having difficulty with. If you are asking how to Read Data from Firebase, it's pretty well covered in the documentation. To do your structure 'right' we would need more information. i.e. are you going to query your child nodes? If so, what for? How your data is structured is directly related to what you want to get out of it. Write some code and update your question when you get stuck.
    – Jay
    Nov 25 at 13:27




















  • This isn't a code writing service but we will be happy to help you with existing code you're having difficulty with. If you are asking how to Read Data from Firebase, it's pretty well covered in the documentation. To do your structure 'right' we would need more information. i.e. are you going to query your child nodes? If so, what for? How your data is structured is directly related to what you want to get out of it. Write some code and update your question when you get stuck.
    – Jay
    Nov 25 at 13:27


















This isn't a code writing service but we will be happy to help you with existing code you're having difficulty with. If you are asking how to Read Data from Firebase, it's pretty well covered in the documentation. To do your structure 'right' we would need more information. i.e. are you going to query your child nodes? If so, what for? How your data is structured is directly related to what you want to get out of it. Write some code and update your question when you get stuck.
– Jay
Nov 25 at 13:27






This isn't a code writing service but we will be happy to help you with existing code you're having difficulty with. If you are asking how to Read Data from Firebase, it's pretty well covered in the documentation. To do your structure 'right' we would need more information. i.e. are you going to query your child nodes? If so, what for? How your data is structured is directly related to what you want to get out of it. Write some code and update your question when you get stuck.
– Jay
Nov 25 at 13:27














2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










If you are simply reading data and will never query for anything it's pretty straightforward



root
all_data
data_0 //created with .childByAutoId
brand: "7 days"
products:
"Tabak1": true
"Tabak2": true
data_1
brand: "Zomo"
products:
"Tabak1": true
"Tabak2": true
data_3
brand: "Aeon"
products:
"Shisha1": true
"Shisha2": true


however, this will lead to issues* if for example you want to query for all brands that have Tabak2 products. So here's an alternative that would enable you to easily determine the brand nodes that have Tabak2



root
brands
brand_0
brand: "7 days"
brand_1
brand: "Zomo"
brand_2
brand: "Aeon"
products_by_brand
brand_0
"Tabak1": true
"Tabak2": true
brand_1
"Tabak1": true
"Tabak2": true
brand_2
"Shisha1": true
"Shisha2": true


And if you want to be super cool then here's a structure that cross references all products and brands which would allow for a variety of queries and allow you to link single products back to multiple brands and vice-versa



root
brands
brand_0 //created with .childByAutoId
brand: "7 days"
product_0: true //products should probably be in a child node
product_1: true
brand_1
brand: "Zomo"
product_0: true
product_1: true
all_products
product_0
name: "Tabak1"
brand_0: true
brand_1: true
product_1
name: "Tabak2"
brand_0: true
brand_1: true


*this can actually be accomplished via a deep path query






share|improve this answer




























    up vote
    -1
    down vote













    brands -> products -> tobacco -> uniqueId -> name, rating and description



                   -> hookah -> uniqueId -> name, rating and description


    I'm not sure if you need to include the brand in the product details since that would be the main parent.
    Hope this helps :)






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435005%2fhow-do-i-structure-a-firebase-database-for-this-case%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote



      accepted










      If you are simply reading data and will never query for anything it's pretty straightforward



      root
      all_data
      data_0 //created with .childByAutoId
      brand: "7 days"
      products:
      "Tabak1": true
      "Tabak2": true
      data_1
      brand: "Zomo"
      products:
      "Tabak1": true
      "Tabak2": true
      data_3
      brand: "Aeon"
      products:
      "Shisha1": true
      "Shisha2": true


      however, this will lead to issues* if for example you want to query for all brands that have Tabak2 products. So here's an alternative that would enable you to easily determine the brand nodes that have Tabak2



      root
      brands
      brand_0
      brand: "7 days"
      brand_1
      brand: "Zomo"
      brand_2
      brand: "Aeon"
      products_by_brand
      brand_0
      "Tabak1": true
      "Tabak2": true
      brand_1
      "Tabak1": true
      "Tabak2": true
      brand_2
      "Shisha1": true
      "Shisha2": true


      And if you want to be super cool then here's a structure that cross references all products and brands which would allow for a variety of queries and allow you to link single products back to multiple brands and vice-versa



      root
      brands
      brand_0 //created with .childByAutoId
      brand: "7 days"
      product_0: true //products should probably be in a child node
      product_1: true
      brand_1
      brand: "Zomo"
      product_0: true
      product_1: true
      all_products
      product_0
      name: "Tabak1"
      brand_0: true
      brand_1: true
      product_1
      name: "Tabak2"
      brand_0: true
      brand_1: true


      *this can actually be accomplished via a deep path query






      share|improve this answer

























        up vote
        0
        down vote



        accepted










        If you are simply reading data and will never query for anything it's pretty straightforward



        root
        all_data
        data_0 //created with .childByAutoId
        brand: "7 days"
        products:
        "Tabak1": true
        "Tabak2": true
        data_1
        brand: "Zomo"
        products:
        "Tabak1": true
        "Tabak2": true
        data_3
        brand: "Aeon"
        products:
        "Shisha1": true
        "Shisha2": true


        however, this will lead to issues* if for example you want to query for all brands that have Tabak2 products. So here's an alternative that would enable you to easily determine the brand nodes that have Tabak2



        root
        brands
        brand_0
        brand: "7 days"
        brand_1
        brand: "Zomo"
        brand_2
        brand: "Aeon"
        products_by_brand
        brand_0
        "Tabak1": true
        "Tabak2": true
        brand_1
        "Tabak1": true
        "Tabak2": true
        brand_2
        "Shisha1": true
        "Shisha2": true


        And if you want to be super cool then here's a structure that cross references all products and brands which would allow for a variety of queries and allow you to link single products back to multiple brands and vice-versa



        root
        brands
        brand_0 //created with .childByAutoId
        brand: "7 days"
        product_0: true //products should probably be in a child node
        product_1: true
        brand_1
        brand: "Zomo"
        product_0: true
        product_1: true
        all_products
        product_0
        name: "Tabak1"
        brand_0: true
        brand_1: true
        product_1
        name: "Tabak2"
        brand_0: true
        brand_1: true


        *this can actually be accomplished via a deep path query






        share|improve this answer























          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          If you are simply reading data and will never query for anything it's pretty straightforward



          root
          all_data
          data_0 //created with .childByAutoId
          brand: "7 days"
          products:
          "Tabak1": true
          "Tabak2": true
          data_1
          brand: "Zomo"
          products:
          "Tabak1": true
          "Tabak2": true
          data_3
          brand: "Aeon"
          products:
          "Shisha1": true
          "Shisha2": true


          however, this will lead to issues* if for example you want to query for all brands that have Tabak2 products. So here's an alternative that would enable you to easily determine the brand nodes that have Tabak2



          root
          brands
          brand_0
          brand: "7 days"
          brand_1
          brand: "Zomo"
          brand_2
          brand: "Aeon"
          products_by_brand
          brand_0
          "Tabak1": true
          "Tabak2": true
          brand_1
          "Tabak1": true
          "Tabak2": true
          brand_2
          "Shisha1": true
          "Shisha2": true


          And if you want to be super cool then here's a structure that cross references all products and brands which would allow for a variety of queries and allow you to link single products back to multiple brands and vice-versa



          root
          brands
          brand_0 //created with .childByAutoId
          brand: "7 days"
          product_0: true //products should probably be in a child node
          product_1: true
          brand_1
          brand: "Zomo"
          product_0: true
          product_1: true
          all_products
          product_0
          name: "Tabak1"
          brand_0: true
          brand_1: true
          product_1
          name: "Tabak2"
          brand_0: true
          brand_1: true


          *this can actually be accomplished via a deep path query






          share|improve this answer












          If you are simply reading data and will never query for anything it's pretty straightforward



          root
          all_data
          data_0 //created with .childByAutoId
          brand: "7 days"
          products:
          "Tabak1": true
          "Tabak2": true
          data_1
          brand: "Zomo"
          products:
          "Tabak1": true
          "Tabak2": true
          data_3
          brand: "Aeon"
          products:
          "Shisha1": true
          "Shisha2": true


          however, this will lead to issues* if for example you want to query for all brands that have Tabak2 products. So here's an alternative that would enable you to easily determine the brand nodes that have Tabak2



          root
          brands
          brand_0
          brand: "7 days"
          brand_1
          brand: "Zomo"
          brand_2
          brand: "Aeon"
          products_by_brand
          brand_0
          "Tabak1": true
          "Tabak2": true
          brand_1
          "Tabak1": true
          "Tabak2": true
          brand_2
          "Shisha1": true
          "Shisha2": true


          And if you want to be super cool then here's a structure that cross references all products and brands which would allow for a variety of queries and allow you to link single products back to multiple brands and vice-versa



          root
          brands
          brand_0 //created with .childByAutoId
          brand: "7 days"
          product_0: true //products should probably be in a child node
          product_1: true
          brand_1
          brand: "Zomo"
          product_0: true
          product_1: true
          all_products
          product_0
          name: "Tabak1"
          brand_0: true
          brand_1: true
          product_1
          name: "Tabak2"
          brand_0: true
          brand_1: true


          *this can actually be accomplished via a deep path query







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 at 13:40









          Jay

          18.3k42848




          18.3k42848
























              up vote
              -1
              down vote













              brands -> products -> tobacco -> uniqueId -> name, rating and description



                             -> hookah -> uniqueId -> name, rating and description


              I'm not sure if you need to include the brand in the product details since that would be the main parent.
              Hope this helps :)






              share|improve this answer

























                up vote
                -1
                down vote













                brands -> products -> tobacco -> uniqueId -> name, rating and description



                               -> hookah -> uniqueId -> name, rating and description


                I'm not sure if you need to include the brand in the product details since that would be the main parent.
                Hope this helps :)






                share|improve this answer























                  up vote
                  -1
                  down vote










                  up vote
                  -1
                  down vote









                  brands -> products -> tobacco -> uniqueId -> name, rating and description



                                 -> hookah -> uniqueId -> name, rating and description


                  I'm not sure if you need to include the brand in the product details since that would be the main parent.
                  Hope this helps :)






                  share|improve this answer












                  brands -> products -> tobacco -> uniqueId -> name, rating and description



                                 -> hookah -> uniqueId -> name, rating and description


                  I'm not sure if you need to include the brand in the product details since that would be the main parent.
                  Hope this helps :)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 at 16:53









                  Zeel Mehta

                  193




                  193






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435005%2fhow-do-i-structure-a-firebase-database-for-this-case%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      What visual should I use to simply compare current year value vs last year in Power BI desktop

                      How to ignore python UserWarning in pytest?

                      Alexandru Averescu