mardi 19 janvier 2016

The recommended way to save an Ember record with relationship to remote server?

I tried to save a Quote record with a belongsTo relationship.

My Quote model is like this

{
  content: DS.attr('string'),
  member:  DS.belongsTo('member')
}

My Quote record is using this hash for creation

{
  "content": params.content, 
  "member": this.store.findRecord('member', params.id)
}

I have a form so I pass the data to the route, create a new record and save it.

I understand that Ember Data trying to work out the relationship itself by sending a request to the server because I only gave an id and there is no cached data in the store.

But I am not sure this is normal. Why make another request when an ID of that relationship is all for the server to care about.

So I am wondering..what is the best or recommended practice for Ember?

  • Should Ember pre-load all the records that are needed beforehand?
  • Should the model contain a member_id field?
  • or this is really just what must happen - a get request then a post.
  • Or not rely on Ember Data convention but manually write some Ajax post code



Aucun commentaire:

Enregistrer un commentaire