Structuring relationships in Firebase

I have two elements in my Firebase: providersand services, and I'm trying to figure out how to best structure and build relationships using the Firebase approach proposed by a smoothed architecture.

My data looks something like this:

{
  "services" : {
    "hip_replacement" : {
      "title" : "Hip Replacement"
    }
  },

  "providers" : {
    "the_blue_hospital" : {
      "title" : "The Blue Hospital"
    }
  }
}

I would like to link these two items together so that if you visited the Hip Replacement page, the Blue Hospital would appear under it, if you would visit the The Blue Hospital page, Hip Replacement would appear under this, Two-way relationship, in essence.

What would be the best way to structure something like this? I thought of the following lines:

{
  "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": {...
    }
  }
}

Is there a better way to achieve this or a more elegant solution? Any help is appreciated.

Thanks in advance!

+4
1

Firebase , . "". , .

" ", , , . :

{
  "services": {
    "hip_replacement": {}
  },
  "providers": {
    "the_blue_hospital": {...},
    "the_red_hospital": {...},
    "the_green_hospital": {...}
  },
  "serviceProviders": {
    "-JqD5JX0RUDTXsu7Ok3R": {
      "provider": "the_blue_hospital",
      "service": "hip_replacement"
  }
    "-JqDoKfyJqPkQlCXDvFM": {
      "provider": "the_green_hospital",
      "service": "hip_replacement"
  }
    "-JbE7Ji_JRz2bHgBdMWQ": {
      "provider": "the_blue_hospital",
      "service": "hip_replacement"
  }
}

:

Pro

  • , .

Con

  • . Firebase , , . , , , , .
  • , . , , /lodash groupBy() .

:

  • ?
  • ? ( , ..), , ?
+9

Source: https://habr.com/ru/post/1570891/


All Articles