Reputation: 73
Say you have the following model:
App.Item = DS.Model.extend({
owner: DS.belongsTo('App.Person', {embedded: true})
})
This means you can load this embedded association, but it also means that if you want to create a new Item for a person that already exists ember-data will also embed the Person object for every new item.
Is it possible to make it load embedded objects but when creating associations only send the ids? i.e send this instead:
{"item": {"owner_id": 5}}
Edit: To clarify, I want ember-data to load embedded relations, but if I set {embedded: true} this code:
App.Item.createRecord({name: 'Something', owner: App.Person.find(1)});
// And a few moments later when App.Person.find(1) has loaded
App.store.commit()
It will send the following json:
{ "item": {"name": "Something", owner: { id: 1, name: "whatever" }}
But what I want is:
{ "item": {"name": "Something", owner_id: 1 }}
Basically if I set embedded = true ember-data will also embed the assocations when you create an object.
Upvotes: 0
Views: 473
Reputation: 9236
If I correctly understand your aim, you shouldn't have to specify { embedded: true }
. The default ember-data behavior is to be lazy.
It you are using active_model_serializers
(which I strongly recommend to you), you should declare your server-side serializer as follow:
class ItemSerializer < ActiveModel::Serializer
embed :ids, include: false
#...
end
Upvotes: 1