mercredi 26 janvier 2022

Ember embedded model with belongsTo

I have a data model that looks like this on the server:

recipes : {
  <recipe ID> : {
    ingredients : [
      {
        count: 2,
        ingredient: <ingredient ID>
      },
      {
        count: 4,
        ingredient: <ingredient ID>
      }
    ]
  }
},

ingredients : {
  <Ingredient ID> : {...},
  <Ingredient ID> : {...}
}

I want to be able to use the ingredient ID in the recipe as a full Ingredient model object, but I can't figure out the best way of doing that. My server doesn't support Includes. Do I intercept this in a custom serializer and then use store.findRecord? Or is there a more efficient way of setting up my model to support this? I haven't been able to find a way to have the ingredients list as a model because there's no associated ID with an ingredients list, so I've been treating it as a read-only object using @attr on the recipe model.




Aucun commentaire:

Enregistrer un commentaire