I have the id of a model I know should exist, and I would like to create a record with a belongsTo association to this model. However, I would like to only provide the id when creating the association, rather than first query for the associated model. Is this possible?
This is what I would like to work (or some variant of it):
store.createRecord('person', {childId: '1', name: 'billybob'});
This is for a model defined as follows:
Person = DS.Model.extend({
name: DS.attr('string'),
child: DS.belongsTo('child'),
});
The guides suggest something like this:
store.createRecord('person', {child: child, name: 'billybob'});
Where child has already been fetched from the store at some point or is a newly created record.
I was hoping to then return the child side-loaded. This could avoid needing endpoints on the backend to deal directly with children, as they are always handled via the person endpoints.
Since we're only giving the backend the ID, it would need to fail if that record doesn't actually exist.
I've tried various permutations such as:
store.createRecord('person', {child: {id: '1'}, name: 'billybob'});
and have attempted to customize the model's serializer without success.
Any help is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire