title: Structuring Relationships in Firebase
body: <p>I've got two items in my Firebase: <code>providers</code> and <code>services</code>, and I'm trying to figure out the best way to structure and build relationships using Firebase's recommended flattened architecture approach.</p>
  
  <p>My data looks something like this:</p>
  
  <pre><code>{
    "services" : {
      "hip_replacement" : {
        "title" : "Hip Replacement"
      }
    },
  
    "providers" : {
      "the_blue_hospital" : {
        "title" : "The Blue Hospital"
      }
    }
  }
  </code></pre>
  
  <p>I would like to link these two items together so that if you were to visit the Hip Replacement page, The Blue Hospital would show up underneath it, if you were to visit The Blue Hospital page, Hip Replacement would show up underneath that. A two-way relationship, essentially.</p>
  
  <p>What would be the best way to structure something like this? I was thinking along the following lines:</p>
  
  <pre><code>{
    "services": {
      "hip_replacement": {
        "title": "Hip Replacement",
        "providers": {
          "the_blue_hospital": true,
          "the_red_hospital": true
        }
      },
      ...
    },
    "providers": {
      "the_blue_hospital": {
        "title": "The Blue Hospital",
      },
      "the_red_hospital": {...
      },
      "the_green_hospital": {...
      }
    }
  }
  </code></pre>
  
  <p>Is there a better way to achieve this or a more elegant solution? Any help is appreciated.</p>
  
  <p>Thanks in advance!</p>