First, Creating
1. You can create records by calling the CreateRecord method in the store .
Store.createrecord (' Post ', { ' Rails is Omakase ', ' Lorem ipsum '});
2. This store object can be used by This.store in controllers and routes .
3. Although CreateRecord is fairly simple, the only thing to note now is that you cannot assign a promise as a relationship. For example, if you want to set a post 's author property, this will not be implemented if the user 's ID is not loaded into the store:
var This . Store;store.createrecord (' post ', { ' Rails is Omakase ' , ' Lorem ipsum ', Author:store.findRecord (' user ', 1)});
4. However, after this promise is implemented you can set the relationship very well:
var This . Store; var post = Store.createrecord (' Post ', { ' Rails is Omakase ', ' Lorem ipsum '}); Store.findrecord (' user ', 1). Then (function(user) { post.set (' author ', user);});
Second, Deleting Records
Deleting a record is as simple as creating a record. Just call the DS. the DeleteRecord () method on any instance of the Model. This marks the record as isDeleted and therefore removes it from the All () query on the store.
Then using the Save () Delete can be persisted (meaning also deleted on the database). Alternatively, you can use the Destroyrecord method to remove and persist colleagues.
Store.findrecord (' Post ', 1). Then (function(POST) { post.deleterecord (); Post.get (// = = True // = = DELETE to/posts/1}); // ORStore.findrecord (' Post ', 2). Then (function(POST) { // = > DELETE TO/POSTS/2});
7.3 Models--Creating and Deleting Records