mercredi 19 juin 2019

Finding an Ember-Data row created with 'createRecord' and with null id value?

I am using the following pattern in an Ember 3.8 project ...

Situation

When the user navigates to the route foo/add the model function in the Route definition uses createRecord to generate an empty foo record in the Data Store.

The foo/add template uses a Component which implements a form to enter foo details into. The form, in turn, uses an instance of ember-power-select for which an onchange handler is defined in the foo form Component.

Once the form is displayed the user is free to use the power select.

When the onchange handler of the power select fires I want to update the record created initially by createRecord.

Issue

I can send an action to the foo/add Controller but how does the Controller find the row in the Data Store ? Because the row has not yet been inserted on the server it doesn't have the ID which will eventually be associated with it, the id value is in fact null.

Alternatives

I have read some references in old Ember material to being able to generate your own ID at the point of createRecord but I can't find a contemporary reference.

I'm open to a totally different approach so any suggestions welcome.

Finally, although I'm using the Data Store to hold data on the client side I'm not actually using Ember-Data to communicate with the server (not sure that makes any difference but I thought I would make it clear).




Aucun commentaire:

Enregistrer un commentaire