beauby / jsonapi-datastore

JavaScript client-side JSON API data handling made easy.
MIT License
195 stars 40 forks source link

Angular - Create new 'Article' Model before initial sync #21

Closed plwade closed 8 years ago

plwade commented 8 years ago

I have a situation where I would like to create a new 'Article' before I have queried my restAPI and sync'd the results.

This means the following line will not find 'article' in the Model store, because we have not performed an initial sync. var newArticle = new JsonApiDataStore.Model('article');

Any idea how to do this?

Any help appreciated.

Regards,

Paul.

beauby commented 8 years ago

Currently what you could do is:

// c.f. https://github.com/beauby/jsonapi-datastore/blob/master/src/jsonapi-datastore.js#L10
var newArticle = new JsonApiDataStoreModel('article');
newArticle.setAttribute('title', 'Cool Article');
// ...
newArticle.setRelationship('author', user);
// ...

Note that the related models must already exist (which is consistent with the JSON API spec).

plwade commented 8 years ago

Hi Lucas, Thank you for getting back to me so soon:) We have just started developing an Angular app, and it is my job to evaluate the client libraries and get our front end talking to our back end api, so your help is much appreciated. I may have a few more questions along the way, so it would be good if we could stay in touch. Thanks for the help. Regards, Paul.

beauby commented 8 years ago

Hi Paul, No worries, feel free to open as many issues as necessary. Cheers, Lucas

ps: In the meantime, I'll mark this issue as resolved. Feel free to keep commenting should you need further assistance.

plwade commented 8 years ago

Much appreciated:)Thank you.Paul.

Date: Sun, 27 Dec 2015 14:41:59 -0800 From: notifications@github.com To: jsonapi-datastore@noreply.github.com CC: pl_wade@hotmail.com Subject: Re: [jsonapi-datastore] Angular - Create new 'Article' Model before initial sync (#21)

Hi Paul,

No worries, feel free to open as many issues as necessary.

Cheers,

Lucas

— Reply to this email directly or view it on GitHub.