7.3 Models--Creating and Deleting Records

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.