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.store在controllers和routes中使用。
3. 尽管createRecord相当简单,唯一要注意的是你不能分配一个promise作为一个关系。例如,如果你希望设置一个post的author属性,如果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
});
7.3 Models -- Creating And Deleting Records的更多相关文章
- ERROR:"org.apache.zookeeper.KeeperException$NoAuthException: KeeperErrorCode = NoAuth for /config/topics/test" when creating or deleting Kafka operations authorized through the Ranger policies
PROBLEM DESCRIPTION When creating or deleting topics in Kafka, they cannot be authorized through the ...
- Ember.js学习教程 -- 目录
写在前面的话: 公司的新项目需要用到Ember.js,版本为v1.13.0.由于网上关于Ember的资料非常少,所以只有硬着头皮看官网的Guides,为了加深印象和方便以后查阅就用自己拙劣的英语水平把 ...
- Models
Models Models control the data source, they are used for collecting and issuing data, this could be ...
- Database ORM
Database ORM Introduction Basic Usage Mass Assignment Insert, Update, Delete Soft Deleting Timestamp ...
- Professional C# 6 and .NET Core 1.0 - 38 Entity Framework Core
本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - 38 Entity Framework ...
- 学习笔记:The Best of MySQL Forum
http://mysql.rjweb.org/bestof.html I have tagged many of the better forum threads. 'Better' is based ...
- Professional C# 6 and .NET Core 1.0 - Chapter 38 Entity Framework Core
本文内容为转载,重新排版以供学习研究.如有侵权,请联系作者删除. 转载请注明本文出处:Professional C# 6 and .NET Core 1.0 - Chapter 38 Entity F ...
- Local Databases with SQLiteOpenHelper
Overview For maximum control over local data, developers can use SQLite directly by leveraging SQLit ...
- HEC-ResSim原文档
HEC-ResSim Reservoir System Simulation User's Manual Version 3.1 May 201 ...
随机推荐
- ios开发之--NSString和NSArray互转
将string字符串转换为array数组 NSArray *array = [Str componentsSeparatedByString:@","];//分隔符逗号 将arr ...
- python常用BIF汇总
append():在列表末尾增加一个数据项:例如a.append('hello') pop():用于移除列表中的一个元素(默认最后一个元素),并且返回该元素的值:例如a.pop() extend(): ...
- request.get... getHeader 能取得的信息 参数
转载▼ StringTokenizer st = new StringTokenizer(agent,";"); st.nextToken(); //得到用户的浏览器名 Str ...
- ipmi监控主机
author: headsen chen date: 2018-09-25 20:04:01 IPMI介绍 IPMI(Intelligent Platform Management ...
- 【BZOJ2957】楼房重建 分块
[BZOJ2957]楼房重建 Description 小A的楼房外有一大片施工工地,工地上有N栋待建的楼房.每天,这片工地上的房子拆了又建.建了又拆.他经常无聊地看着窗外发呆,数自己能够看到多少栋房子 ...
- 【Android】安卓中常用的图片加载方法
一.通过相机选图片: 布局文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout x ...
- Android中Log机制详解
Android中Log的输出有如下几种: Log.v(String tag, String msg); //VERBOSELog.d(String tag, String msg); ...
- angularJS的过滤器!
angularJS过滤器: filter currency date filter json limitTo lowercase number orderBy uppercase ...... Fil ...
- poj3349 Snowflake Snow Snowflakes【HASH】
Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 49991 Accep ...
- RGBA HSB opengl光照模型
RGBA HSB HSV颜色模型对应于画家的配色的方法.画家用改变色浓和色深的方法来从某种纯色获得不同色调的颜色.其做法是:在一种纯色中加入白色以改变色浓,加入黑色以改变色深,同时加入不同比例的白 ...