Is it possible to pass parameters like this? I need to pass some information that is not part of the model itself.
myModel.save({site : 23})
You can pass options as of Ember Data 2.2. However, you have to remember to pass your options under the adapterOptions
property. For example,
myModel.save({
adapterOptions: {
site: 23
}
});
Inside either of DS.Store#findAll
, DS.Store#findRecord
, DS.Store#query
, DS.Model#save
and DS.Model#destroyRecord
, one of the parameters should now have adapterOptions
. In the case of DS.Model#save
, you can override updateRecord
in your adapter:
export default DS.Adapter.extend({
updateRecord(store, type, snapshot) {
// will now have `snapshot.adapterOptions`.
// ...
}
});
It is possible if you:
serializeIntoHash
method.For instance:
App.Model = DS.Model.extend({
//...
site: DS.attr('number', { serialize: false })
});
App.ModelSerializer = DS.RESTSerializer.extend({
serializeIntoHash: function(hash, type, record, options) {
this._super(hash, type, record, options);
Ember.merge(hash, {
'site': record.get('site')
});
}
});
See this comment, this is the correct way to achieve your goal.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With