@ikarius wrote:
I'm bringing up a rails-api/AMS back-end and an ember front-end, connected via jsonapi adapters.
I've set up support for "include" directives on a page that references a client model, and it's distributor parent (belongsTo relationship). I see Ember make the request to the jsonapi endpoint with the include directive, I see the back-end response come back with the distributor included, but then Ember immediately goes and does another GET to (re) fetch the distributor. I'm kind-of guessing this is promise-fulfillment going awry, but I don't know. Here's what I've got:
Client model:
import DS from 'ember-data';
import Organization from './organization';export default Organization.extend({
name: DS.attr('string'),
address1: DS.attr('string'),
distributor: DS.belongsTo('distributor', { async: true })
});Distributor model:
import DS from 'ember-data';
import Organization from './organization';export default Organization.extend({
name: DS.attr('string'),
address1: DS.attr('string'),
clients: DS.hasMany('client', { async: true } )
});Client show route:
export default Ember.Route.extend({
model(params) {
return this.store.findRecord('client', params.client_id, { include: 'distributor' } );
},
});Client show template references to distributor:
{{model.distributor.id}} - {{model.distributor.name}}
First HTTP request:
http://myserver.local:3000/api/v1/clients/2?include=distributor GET
Response:
{"data":{"id":"2","type":"clients","attributes":{"name":"B Client","address1":"112 Other Place"},"relationships":{"distributor":{"data":{"id":"2","type":"distributors"}},"users":{"data":[]}}},"included":[{"id":"2","type":"distributors","attributes":{"name":"Another Distributor","address1":"102 Some Place"},"relationships":{"clients":{"data":[{"id":"2","type":"clients"}]},"users":{"data":[]}}}]}
And that request is immediately followed by another request:
So- the point of the include directive is to allow me to specify additional data to be loaded with a single request. Any ideas why I'm getting the second request?
Posts: 1
Participants: 1