mercredi 26 juin 2019

Why does a `hasMany` relationship create an OPTIONS and GET request for each item in the relationship?

I currently have a response like so from my API:

{
  "data": [{
      "attributes": {
        "customer_name": "The Name",
      },
      "id": 1,
      "relationships": {
        "tasks": {
          "data": [{
              "attributes": {
                "name": "The task",
              },

            ]
          }
        },
        "type": "customer"
      }
    ]
  }

And Ember loads the model correctly. However, when I try and consume the computed property the relationship creates, Ember initiates an OPTIONS and subsequent GET request for each item in the relationship.

I haven't worked with these kinds of relationships before so this may be the expected behaviour but I'm a bit confused.

If it is going to do a request for each one, why bother sending the items as part of the original model via a relationship at all? Why not just do a normal model retrieval which would probably be much quicker.

It seems really wasteful so I suspect I'm not handling or understanding something correctly, I'd appreciate any insight.




Aucun commentaire:

Enregistrer un commentaire