7.3 Models -- Creating And Deleting Records

一、Creating

1. 你可以通过调用在store中的createRecord方法来创建records。

store.createRecord(‘post‘, {
  title: ‘Rails is Omakase‘,
  body: ‘Lorem ipsum‘
});

2. 这个store对象可以通过this.storecontrollersroutes中使用。

3. 尽管createRecord相当简单,唯一要注意的目前是你不能分配一个promise作为一个关系。例如,如果你希望设置一个postauthor属性,如果user的id没有被加载进store,这将不会实现:

var store = this.store;

store.createRecord(‘post‘, {
  title: ‘Rails is Omakase‘,
  body: ‘Lorem ipsum‘,
  author: store.findRecord(‘user‘, 1)
});

4. 然而,在这个promise实现之后你可以很容的设置关系:

var store = this.store;

var post = store.createRecord(‘post‘, {
  title: ‘Rails is Omakase‘,
  body: ‘Lorem ipsum‘
});

store.findRecord(‘user‘, 1).then(function(user) {
  post.set(‘author‘, user);
});

二、Deleting records

删除记录和创建记录一样简单。仅仅是调用 DS.Model任意实例上的deleteRecord()方法。这标记这个record是isDeleted并且因此从store上的all()查询上移除它。

然后使用save()删除可以被持久化(指在数据库上也删除)。或者,你可以使用destroyRecord方法同事删除并持久化。

store.findRecord(‘post‘, 1).then(function(post) {
  post.deleteRecord();
  post.get(‘isDeleted‘); // => true
  post.save(); // => DELETE to /posts/1
});

// OR
store.findRecord(‘post‘, 2).then(function(post) {
  post.destroyRecord(); // => DELETE to /posts/2
});
时间: 2024-08-06 17:00:29

7.3 Models -- Creating And Deleting Records的相关文章

hybris Models

---恢复内容开始--- Models是hybris项目中的一种表现形式,每个item中的配置都有一个与之对应的models类.一个Model包含不同扩展中这个项目的所有属性,从而能直接访问到项目中所有的数据. 他比我们正常JAVA中的pojo要更轻量级并且不需要存储,因此更容易模拟和测试. 基本 Model hybris 有2个基础的Model 1.generation Model类,hybris  Commerce Suite 编译时完成 2.Model 生命周期,在hybris  Comm

Local Databases with SQLiteOpenHelper

Overview For maximum control over local data, developers can use SQLite directly by leveraging SQLiteOpenHelper for executing SQL requests and managing a local database. In this guide, we'll use the example of building a database to persist user crea

对象文件映射(ODM (Object-Document Mapper))

除了可以 映射关系数据库的表 之外,Phalcon还可以使用NoSQL数据库如MongoDB等.Phalcon中的ODM具有可以非常容易的实现如下功能:CRUD,事件,验证等. 因为NoSQL数据库中无sql查询及计划等操作故可以提高数据操作的性能.再者,由于无SQL语句创建的操作故可以减少SQL注入的危险. 当前Phalcon中支持的NosSQL数据库如下: 名称 描述 MongoDB MongoDB是一个稳定的高性能的开源的NoSQL数据 创建模型(Creating Models)? NoS

Professional C# 6 and .NET Core 1.0 - 38 Entity Framework Core

本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 38 Entity Framework Core ----------------------------------------------------------------------- What's In This Chapter? Introducing Entity Framework Core 1.0 Using Depe

Database ORM

Database ORM Introduction Basic Usage Mass Assignment Insert, Update, Delete Soft Deleting Timestamps Query Scopes Relationships Querying Relations Eager Loading Inserting Related Models Touching Parent Timestamps Working With Pivot Tables Collection

AWS & ASP.NET

https://dotnetcodr.com/amazon-cloud/ Amazon cloud Big Data overall architecture Architecture of a Big Data messaging and aggregation system using Amazon Web Services part 1 Architecture of a Big Data messaging and aggregation system using Amazon Web

Phalcon之教程 2:INVO 项目讲解(Tutorial 2: Explaining INVO)

教程 2:INVO 项目讲解(Tutorial 2: Explaining INVO) In this second tutorial, we'll explain a more complete application in order to deepen the development with Phalcon. INVO is one of the applications we have created as samples. INVO is a small website that a

【ASP.NET Identity系列教程(二)】运用ASP.NET Identity

注:本文是[ASP.NET Identity系列教程]的第二篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序的用户管理,以及实现应用程序的认证与授权等相关技术,译者希望本系列教程能成为掌握ASP.NET Identity技术的一份完整而有价值的资料.读者若是能够按照文章的描述,一边阅读.一边实践.一边理解,定能有意想不到的巨大收获!希望本系列博文能够得到广大园友的高度推荐. 14 Applying ASP

Content Providers的步骤,来自官网文档

Content Providers In this document Content provider basics Querying a content provider Modifying data in a provider Creating a content provider Content URI summary Key classes ContentProvider ContentResolver Cursor Content providers store and retriev