ember-data-source 1.0.0.beta.7 → 1.0.0.beta.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dist/ember-data.js +1484 -563
- data/dist/ember-data.min.js +4 -4
- data/dist/ember-data.prod.js +1478 -559
- data/lib/ember/data/version.rb +5 -1
- data/package.json +34 -0
- metadata +8 -9
- data/VERSION +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd4aa876cc306a2a0cbff22651c995e2e160c386
|
4
|
+
data.tar.gz: e121beba0aff64936804f83dfb014c736fb3842d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a48bfb3adeaa4d01171de31c46aac67fefdc51460aafa0d595ea19497e8341a2b5a31f54b8340f5a9357d399d49502b636a071905ab9d07924ca508c51c5474c
|
7
|
+
data.tar.gz: 5bbe514b57a289565a45e68b5a1d851f6fde71bf48b9c83645ba8c987eaca8c7fd21b33bc67d4bcb08266fb2806fc6c7fe1e4460db7ed7b900352b117326442c
|
data/dist/ember-data.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* @copyright Copyright 2011-2014 Tilde Inc. and contributors.
|
4
4
|
* Portions Copyright 2011 LivingSocial Inc.
|
5
5
|
* @license Licensed under MIT license (see license.js)
|
6
|
-
* @version 1.0.0-beta.
|
6
|
+
* @version 1.0.0-beta.8.2a68c63a
|
7
7
|
*/
|
8
8
|
(function(global) {
|
9
9
|
var define, requireModule, require, requirejs;
|
@@ -60,44 +60,37 @@ var define, requireModule, require, requirejs;
|
|
60
60
|
};
|
61
61
|
})();
|
62
62
|
|
63
|
-
define("activemodel-adapter/lib/initializers",
|
64
|
-
["../../ember-data/lib/system/container_proxy","./system/active_model_serializer","./system/active_model_adapter"],
|
65
|
-
function(__dependency1__, __dependency2__, __dependency3__) {
|
66
|
-
"use strict";
|
67
|
-
var ContainerProxy = __dependency1__["default"];
|
68
|
-
var ActiveModelSerializer = __dependency2__["default"];
|
69
|
-
var ActiveModelAdapter = __dependency3__["default"];
|
70
|
-
|
71
|
-
Ember.onLoad('Ember.Application', function(Application) {
|
72
|
-
Application.initializer({
|
73
|
-
name: "activeModelAdapter",
|
74
|
-
|
75
|
-
initialize: function(container, application) {
|
76
|
-
var proxy = new ContainerProxy(container);
|
77
|
-
proxy.registerDeprecations([
|
78
|
-
{deprecated: 'serializer:_ams', valid: 'serializer:-active-model'},
|
79
|
-
{deprecated: 'adapter:_ams', valid: 'adapter:-active-model'}
|
80
|
-
]);
|
81
|
-
|
82
|
-
application.register('serializer:-active-model', ActiveModelSerializer);
|
83
|
-
application.register('adapter:-active-model', ActiveModelAdapter);
|
84
|
-
}
|
85
|
-
});
|
86
|
-
});
|
87
|
-
});
|
88
63
|
define("activemodel-adapter/lib/main",
|
89
|
-
["./system","
|
90
|
-
function(__dependency1__,
|
64
|
+
["./system","exports"],
|
65
|
+
function(__dependency1__, __exports__) {
|
91
66
|
"use strict";
|
92
67
|
var ActiveModelAdapter = __dependency1__.ActiveModelAdapter;
|
93
68
|
var ActiveModelSerializer = __dependency1__.ActiveModelSerializer;
|
94
69
|
var EmbeddedRecordsMixin = __dependency1__.EmbeddedRecordsMixin;
|
95
70
|
|
96
|
-
|
97
71
|
__exports__.ActiveModelAdapter = ActiveModelAdapter;
|
98
72
|
__exports__.ActiveModelSerializer = ActiveModelSerializer;
|
99
73
|
__exports__.EmbeddedRecordsMixin = EmbeddedRecordsMixin;
|
100
74
|
});
|
75
|
+
define("activemodel-adapter/lib/setup-container",
|
76
|
+
["../../ember-data/lib/system/container_proxy","./system/active_model_serializer","./system/active_model_adapter","exports"],
|
77
|
+
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
|
78
|
+
"use strict";
|
79
|
+
var ContainerProxy = __dependency1__["default"];
|
80
|
+
var ActiveModelSerializer = __dependency2__["default"];
|
81
|
+
var ActiveModelAdapter = __dependency3__["default"];
|
82
|
+
|
83
|
+
__exports__["default"] = function setupActiveModelAdapter(container, application){
|
84
|
+
var proxy = new ContainerProxy(container);
|
85
|
+
proxy.registerDeprecations([
|
86
|
+
{deprecated: 'serializer:_ams', valid: 'serializer:-active-model'},
|
87
|
+
{deprecated: 'adapter:_ams', valid: 'adapter:-active-model'}
|
88
|
+
]);
|
89
|
+
|
90
|
+
container.register('serializer:-active-model', ActiveModelSerializer);
|
91
|
+
container.register('adapter:-active-model', ActiveModelAdapter);
|
92
|
+
};
|
93
|
+
});
|
101
94
|
define("activemodel-adapter/lib/system",
|
102
95
|
["./system/embedded_records_mixin","./system/active_model_adapter","./system/active_model_serializer","exports"],
|
103
96
|
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
|
@@ -130,10 +123,11 @@ define("activemodel-adapter/lib/system/active_model_adapter",
|
|
130
123
|
|
131
124
|
/**
|
132
125
|
The ActiveModelAdapter is a subclass of the RESTAdapter designed to integrate
|
133
|
-
with a JSON API that uses an underscored naming convention instead of
|
126
|
+
with a JSON API that uses an underscored naming convention instead of camelCasing.
|
134
127
|
It has been designed to work out of the box with the
|
135
128
|
[active_model_serializers](http://github.com/rails-api/active_model_serializers)
|
136
|
-
Ruby gem.
|
129
|
+
Ruby gem. This Adapter expects specific settings using ActiveModel::Serializers,
|
130
|
+
`embed :ids, include: true` which sideloads the records.
|
137
131
|
|
138
132
|
This adapter extends the DS.RESTAdapter by making consistent use of the camelization,
|
139
133
|
decamelization and pluralization methods to normalize the serialized JSON into a
|
@@ -174,7 +168,7 @@ define("activemodel-adapter/lib/system/active_model_adapter",
|
|
174
168
|
@class ActiveModelAdapter
|
175
169
|
@constructor
|
176
170
|
@namespace DS
|
177
|
-
@extends DS.
|
171
|
+
@extends DS.RESTAdapter
|
178
172
|
**/
|
179
173
|
|
180
174
|
var ActiveModelAdapter = RESTAdapter.extend({
|
@@ -190,7 +184,7 @@ define("activemodel-adapter/lib/system/active_model_adapter",
|
|
190
184
|
|
191
185
|
@method pathForType
|
192
186
|
@param {String} type
|
193
|
-
@
|
187
|
+
@return String
|
194
188
|
*/
|
195
189
|
pathForType: function(type) {
|
196
190
|
var decamelized = decamelize(type);
|
@@ -212,7 +206,7 @@ define("activemodel-adapter/lib/system/active_model_adapter",
|
|
212
206
|
|
213
207
|
@method ajaxError
|
214
208
|
@param jqXHR
|
215
|
-
@
|
209
|
+
@return error
|
216
210
|
*/
|
217
211
|
ajaxError: function(jqXHR) {
|
218
212
|
var error = this._super(jqXHR);
|
@@ -254,16 +248,65 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
254
248
|
capitalize = Ember.String.capitalize,
|
255
249
|
decamelize = Ember.String.decamelize,
|
256
250
|
underscore = Ember.String.underscore;
|
251
|
+
/**
|
252
|
+
The ActiveModelSerializer is a subclass of the RESTSerializer designed to integrate
|
253
|
+
with a JSON API that uses an underscored naming convention instead of camelCasing.
|
254
|
+
It has been designed to work out of the box with the
|
255
|
+
[active_model_serializers](http://github.com/rails-api/active_model_serializers)
|
256
|
+
Ruby gem. This Serializer expects specific settings using ActiveModel::Serializers,
|
257
|
+
`embed :ids, include: true` which sideloads the records.
|
258
|
+
|
259
|
+
This serializer extends the DS.RESTSerializer by making consistent
|
260
|
+
use of the camelization, decamelization and pluralization methods to
|
261
|
+
normalize the serialized JSON into a format that is compatible with
|
262
|
+
a conventional Rails backend and Ember Data.
|
263
|
+
|
264
|
+
## JSON Structure
|
257
265
|
|
266
|
+
The ActiveModelSerializer expects the JSON returned from your server
|
267
|
+
to follow the REST adapter conventions substituting underscored keys
|
268
|
+
for camelcased ones.
|
269
|
+
|
270
|
+
### Conventional Names
|
271
|
+
|
272
|
+
Attribute names in your JSON payload should be the underscored versions of
|
273
|
+
the attributes in your Ember.js models.
|
274
|
+
|
275
|
+
For example, if you have a `Person` model:
|
276
|
+
|
277
|
+
```js
|
278
|
+
App.FamousPerson = DS.Model.extend({
|
279
|
+
firstName: DS.attr('string'),
|
280
|
+
lastName: DS.attr('string'),
|
281
|
+
occupation: DS.attr('string')
|
282
|
+
});
|
283
|
+
```
|
284
|
+
|
285
|
+
The JSON returned should look like this:
|
286
|
+
|
287
|
+
```js
|
288
|
+
{
|
289
|
+
"famous_person": {
|
290
|
+
"first_name": "Barack",
|
291
|
+
"last_name": "Obama",
|
292
|
+
"occupation": "President"
|
293
|
+
}
|
294
|
+
}
|
295
|
+
```
|
296
|
+
|
297
|
+
@class ActiveModelSerializer
|
298
|
+
@namespace DS
|
299
|
+
@extends DS.RESTSerializer
|
300
|
+
*/
|
258
301
|
var ActiveModelSerializer = RESTSerializer.extend({
|
259
302
|
// SERIALIZE
|
260
303
|
|
261
304
|
/**
|
262
|
-
Converts
|
305
|
+
Converts camelCased attributes to underscored when serializing.
|
263
306
|
|
264
307
|
@method keyForAttribute
|
265
308
|
@param {String} attribute
|
266
|
-
@
|
309
|
+
@return String
|
267
310
|
*/
|
268
311
|
keyForAttribute: function(attr) {
|
269
312
|
return decamelize(attr);
|
@@ -276,7 +319,7 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
276
319
|
@method keyForRelationship
|
277
320
|
@param {String} key
|
278
321
|
@param {String} kind
|
279
|
-
@
|
322
|
+
@return String
|
280
323
|
*/
|
281
324
|
keyForRelationship: function(key, kind) {
|
282
325
|
key = decamelize(key);
|
@@ -289,7 +332,7 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
289
332
|
}
|
290
333
|
},
|
291
334
|
|
292
|
-
|
335
|
+
/*
|
293
336
|
Does not serialize hasMany relationships by default.
|
294
337
|
*/
|
295
338
|
serializeHasMany: Ember.K,
|
@@ -319,29 +362,19 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
319
362
|
serializePolymorphicType: function(record, json, relationship) {
|
320
363
|
var key = relationship.key,
|
321
364
|
belongsTo = get(record, key);
|
322
|
-
|
323
|
-
|
365
|
+
|
366
|
+
if (belongsTo) {
|
367
|
+
key = this.keyForAttribute(key);
|
368
|
+
json[key + "_type"] = capitalize(belongsTo.constructor.typeKey);
|
369
|
+
}
|
324
370
|
},
|
325
371
|
|
326
372
|
// EXTRACT
|
327
373
|
|
328
374
|
/**
|
329
|
-
|
330
|
-
|
331
|
-
@method typeForRoot
|
332
|
-
@param {String} root
|
333
|
-
@returns String the model's typeKey
|
334
|
-
*/
|
335
|
-
typeForRoot: function(root) {
|
336
|
-
var camelized = camelize(root);
|
337
|
-
return singularize(camelized);
|
338
|
-
},
|
339
|
-
|
340
|
-
/**
|
341
|
-
Add extra step to `DS.RESTSerializer.normalize` so links are
|
342
|
-
normalized.
|
375
|
+
Add extra step to `DS.RESTSerializer.normalize` so links are normalized.
|
343
376
|
|
344
|
-
If your payload looks like
|
377
|
+
If your payload looks like:
|
345
378
|
|
346
379
|
```js
|
347
380
|
{
|
@@ -352,6 +385,7 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
352
385
|
}
|
353
386
|
}
|
354
387
|
```
|
388
|
+
|
355
389
|
The normalized version would look like this
|
356
390
|
|
357
391
|
```js
|
@@ -368,7 +402,7 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
368
402
|
@param {subclass of DS.Model} type
|
369
403
|
@param {Object} hash
|
370
404
|
@param {String} prop
|
371
|
-
@
|
405
|
+
@return Object
|
372
406
|
*/
|
373
407
|
|
374
408
|
normalize: function(type, hash, prop) {
|
@@ -381,7 +415,7 @@ define("activemodel-adapter/lib/system/active_model_serializer",
|
|
381
415
|
Convert `snake_cased` links to `camelCase`
|
382
416
|
|
383
417
|
@method normalizeLinks
|
384
|
-
@param {Object}
|
418
|
+
@param {Object} data
|
385
419
|
*/
|
386
420
|
|
387
421
|
normalizeLinks: function(data){
|
@@ -460,24 +494,83 @@ define("activemodel-adapter/lib/system/embedded_records_mixin",
|
|
460
494
|
"use strict";
|
461
495
|
var get = Ember.get;
|
462
496
|
var forEach = Ember.EnumerableUtils.forEach;
|
497
|
+
var camelize = Ember.String.camelize;
|
463
498
|
|
464
499
|
var pluralize = __dependency1__.pluralize;
|
465
500
|
|
466
501
|
/**
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
502
|
+
## Using Embedded Records
|
503
|
+
|
504
|
+
`DS.EmbeddedRecordsMixin` supports serializing embedded records.
|
505
|
+
|
506
|
+
To set up embedded records, include the mixin when extending a serializer
|
507
|
+
then define and configure embedded (model) relationships.
|
508
|
+
|
509
|
+
Below is an example of a per-type serializer ('post' type).
|
471
510
|
|
472
511
|
```js
|
473
512
|
App.PostSerializer = DS.ActiveModelSerializer.extend(DS.EmbeddedRecordsMixin, {
|
474
513
|
attrs: {
|
475
|
-
|
514
|
+
author: {embedded: 'always'},
|
515
|
+
comments: {serialize: 'ids'}
|
476
516
|
}
|
477
517
|
})
|
478
518
|
```
|
479
519
|
|
480
|
-
|
520
|
+
The `attrs` option for a resource `{embedded: 'always'}` is shorthand for:
|
521
|
+
|
522
|
+
```js
|
523
|
+
{serialize: 'records', deserialize: 'records'}
|
524
|
+
```
|
525
|
+
|
526
|
+
### Configuring Attrs
|
527
|
+
|
528
|
+
A resource's `attrs` option may be set to use `ids`, `records` or `no` for the
|
529
|
+
`serialize` and `deserialize` settings.
|
530
|
+
|
531
|
+
The `attrs` property can be set on the ApplicationSerializer or a per-type
|
532
|
+
serializer.
|
533
|
+
|
534
|
+
In the case where embedded JSON is expected while extracting a payoad (reading)
|
535
|
+
the setting is `deserialize: 'records'`, there is no need to use `ids` when
|
536
|
+
extracting as that is the default behavior without this mixin if you are using
|
537
|
+
the vanilla ActiveModelAdapter. Likewise, to embed JSON in the payload while
|
538
|
+
serializing `serialize: 'records'` is the setting to use. There is an option of
|
539
|
+
not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you
|
540
|
+
do not want the relationship sent at all, you can use `serialize: 'no'`.
|
541
|
+
|
542
|
+
|
543
|
+
### ActiveModelSerializer defaults
|
544
|
+
If you do not overwrite `attrs` for a specific relationship, the `ActiveModelSerializer`
|
545
|
+
will behave in the following way:
|
546
|
+
|
547
|
+
BelongsTo: `{serialize:'id', deserialize:'id'}`
|
548
|
+
HasMany: `{serialize:no, deserialize:'ids'}`
|
549
|
+
|
550
|
+
### Model Relationships
|
551
|
+
|
552
|
+
Embedded records must have a model defined to be extracted and serialized.
|
553
|
+
|
554
|
+
To successfully extract and serialize embedded records the model relationships
|
555
|
+
must be setup correcty See the
|
556
|
+
[defining relationships](/guides/models/defining-models/#toc_defining-relationships)
|
557
|
+
section of the **Defining Models** guide page.
|
558
|
+
|
559
|
+
Records without an `id` property are not considered embedded records, model
|
560
|
+
instances must have an `id` property to be used with Ember Data.
|
561
|
+
|
562
|
+
### Example JSON payloads, Models and Serializers
|
563
|
+
|
564
|
+
**When customizing a serializer it is imporant to grok what the cusomizations
|
565
|
+
are, please read the docs for the methods this mixin provides, in case you need
|
566
|
+
to modify to fit your specific needs.**
|
567
|
+
|
568
|
+
For example review the docs for each method of this mixin:
|
569
|
+
|
570
|
+
* [extractArray](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_extractArray)
|
571
|
+
* [extractSingle](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_extractSingle)
|
572
|
+
* [serializeBelongsTo](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeBelongsTo)
|
573
|
+
* [serializeHasMany](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeHasMany)
|
481
574
|
|
482
575
|
@class EmbeddedRecordsMixin
|
483
576
|
@namespace DS
|
@@ -485,102 +578,457 @@ define("activemodel-adapter/lib/system/embedded_records_mixin",
|
|
485
578
|
var EmbeddedRecordsMixin = Ember.Mixin.create({
|
486
579
|
|
487
580
|
/**
|
488
|
-
Serialize
|
581
|
+
Serialize `belongsTo` relationship when it is configured as an embedded object.
|
582
|
+
|
583
|
+
This example of an author model belongs to a post model:
|
584
|
+
|
585
|
+
```js
|
586
|
+
Post = DS.Model.extend({
|
587
|
+
title: DS.attr('string'),
|
588
|
+
body: DS.attr('string'),
|
589
|
+
author: DS.belongsTo('author')
|
590
|
+
});
|
591
|
+
|
592
|
+
Author = DS.Model.extend({
|
593
|
+
name: DS.attr('string'),
|
594
|
+
post: DS.belongsTo('post')
|
595
|
+
});
|
596
|
+
```
|
597
|
+
|
598
|
+
Use a custom (type) serializer for the post model to configure embedded author
|
599
|
+
|
600
|
+
```js
|
601
|
+
App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
|
602
|
+
attrs: {
|
603
|
+
author: {embedded: 'always'}
|
604
|
+
}
|
605
|
+
})
|
606
|
+
```
|
607
|
+
|
608
|
+
A payload with an attribute configured for embedded records can serialize
|
609
|
+
the records together under the root attribute's payload:
|
610
|
+
|
611
|
+
```js
|
612
|
+
{
|
613
|
+
"post": {
|
614
|
+
"id": "1"
|
615
|
+
"title": "Rails is omakase",
|
616
|
+
"author": {
|
617
|
+
"id": "2"
|
618
|
+
"name": "dhh"
|
619
|
+
}
|
620
|
+
}
|
621
|
+
}
|
622
|
+
```
|
623
|
+
|
624
|
+
@method serializeBelongsTo
|
625
|
+
@param {DS.Model} record
|
626
|
+
@param {Object} json
|
627
|
+
@param {Object} relationship
|
628
|
+
*/
|
629
|
+
serializeBelongsTo: function(record, json, relationship) {
|
630
|
+
var attr = relationship.key;
|
631
|
+
var attrs = this.get('attrs');
|
632
|
+
if (noSerializeOptionSpecified(attrs, attr)) {
|
633
|
+
this._super(record, json, relationship);
|
634
|
+
return;
|
635
|
+
}
|
636
|
+
var includeIds = hasSerializeIdsOption(attrs, attr);
|
637
|
+
var includeRecords = hasSerializeRecordsOption(attrs, attr);
|
638
|
+
var embeddedRecord = record.get(attr);
|
639
|
+
if (includeIds) {
|
640
|
+
key = this.keyForRelationship(attr, relationship.kind);
|
641
|
+
if (!embeddedRecord) {
|
642
|
+
json[key] = null;
|
643
|
+
} else {
|
644
|
+
json[key] = get(embeddedRecord, 'id');
|
645
|
+
}
|
646
|
+
} else if (includeRecords) {
|
647
|
+
var key = this.keyForRelationship(attr);
|
648
|
+
if (!embeddedRecord) {
|
649
|
+
json[key] = null;
|
650
|
+
} else {
|
651
|
+
json[key] = embeddedRecord.serialize({includeId: true});
|
652
|
+
this.removeEmbeddedForeignKey(record, embeddedRecord, relationship, json[key]);
|
653
|
+
}
|
654
|
+
}
|
655
|
+
},
|
656
|
+
|
657
|
+
/**
|
658
|
+
Serialize `hasMany` relationship when it is configured as embedded objects.
|
659
|
+
|
660
|
+
This example of a post model has many comments:
|
661
|
+
|
662
|
+
```js
|
663
|
+
Post = DS.Model.extend({
|
664
|
+
title: DS.attr('string'),
|
665
|
+
body: DS.attr('string'),
|
666
|
+
comments: DS.hasMany('comment')
|
667
|
+
});
|
668
|
+
|
669
|
+
Comment = DS.Model.extend({
|
670
|
+
body: DS.attr('string'),
|
671
|
+
post: DS.belongsTo('post')
|
672
|
+
});
|
673
|
+
```
|
674
|
+
|
675
|
+
Use a custom (type) serializer for the post model to configure embedded comments
|
676
|
+
|
677
|
+
```js
|
678
|
+
App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
|
679
|
+
attrs: {
|
680
|
+
comments: {embedded: 'always'}
|
681
|
+
}
|
682
|
+
})
|
683
|
+
```
|
684
|
+
|
685
|
+
A payload with an attribute configured for embedded records can serialize
|
686
|
+
the records together under the root attribute's payload:
|
687
|
+
|
688
|
+
```js
|
689
|
+
{
|
690
|
+
"post": {
|
691
|
+
"id": "1"
|
692
|
+
"title": "Rails is omakase",
|
693
|
+
"body": "I want this for my ORM, I want that for my template language..."
|
694
|
+
"comments": [{
|
695
|
+
"id": "1",
|
696
|
+
"body": "Rails is unagi"
|
697
|
+
}, {
|
698
|
+
"id": "2",
|
699
|
+
"body": "Omakase O_o"
|
700
|
+
}]
|
701
|
+
}
|
702
|
+
}
|
703
|
+
```
|
704
|
+
|
705
|
+
The attrs options object can use more specific instruction for extracting and
|
706
|
+
serializing. When serializing, an option to embed `ids` or `records` can be set.
|
707
|
+
When extracting the only option is `records`.
|
708
|
+
|
709
|
+
So `{embedded: 'always'}` is shorthand for:
|
710
|
+
`{serialize: 'records', deserialize: 'records'}`
|
711
|
+
|
712
|
+
To embed the `ids` for a related object (using a hasMany relationship):
|
713
|
+
|
714
|
+
```js
|
715
|
+
App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
|
716
|
+
attrs: {
|
717
|
+
comments: {serialize: 'ids', deserialize: 'records'}
|
718
|
+
}
|
719
|
+
})
|
720
|
+
```
|
721
|
+
|
722
|
+
```js
|
723
|
+
{
|
724
|
+
"post": {
|
725
|
+
"id": "1"
|
726
|
+
"title": "Rails is omakase",
|
727
|
+
"body": "I want this for my ORM, I want that for my template language..."
|
728
|
+
"comments": ["1", "2"]
|
729
|
+
}
|
730
|
+
}
|
731
|
+
```
|
489
732
|
|
490
733
|
@method serializeHasMany
|
734
|
+
@param {DS.Model} record
|
735
|
+
@param {Object} json
|
736
|
+
@param {Object} relationship
|
491
737
|
*/
|
492
738
|
serializeHasMany: function(record, json, relationship) {
|
493
|
-
var
|
494
|
-
|
495
|
-
|
739
|
+
var attr = relationship.key;
|
740
|
+
var attrs = this.get('attrs');
|
741
|
+
if (noSerializeOptionSpecified(attrs, attr)) {
|
742
|
+
this._super(record, json, relationship);
|
743
|
+
return;
|
744
|
+
}
|
745
|
+
var includeIds = hasSerializeIdsOption(attrs, attr);
|
746
|
+
var includeRecords = hasSerializeRecordsOption(attrs, attr);
|
747
|
+
var key;
|
748
|
+
if (includeIds) {
|
749
|
+
key = this.keyForRelationship(attr, relationship.kind);
|
750
|
+
json[key] = get(record, attr).mapBy('id');
|
751
|
+
} else if (includeRecords) {
|
752
|
+
key = this.keyForAttribute(attr);
|
753
|
+
json[key] = get(record, attr).map(function(embeddedRecord) {
|
754
|
+
var serializedEmbeddedRecord = embeddedRecord.serialize({includeId: true});
|
755
|
+
this.removeEmbeddedForeignKey(record, embeddedRecord, relationship, serializedEmbeddedRecord);
|
756
|
+
return serializedEmbeddedRecord;
|
757
|
+
}, this);
|
758
|
+
}
|
759
|
+
},
|
496
760
|
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
primaryKey = get(this, 'primaryKey');
|
761
|
+
/**
|
762
|
+
When serializing an embedded record, modify the property (in the json payload)
|
763
|
+
that refers to the parent record (foreign key for relationship).
|
501
764
|
|
502
|
-
|
765
|
+
Serializing a `belongsTo` relationship removes the property that refers to the
|
766
|
+
parent record
|
503
767
|
|
504
|
-
|
505
|
-
|
768
|
+
Serializing a `hasMany` relationship does not remove the property that refers to
|
769
|
+
the parent record.
|
770
|
+
|
771
|
+
@method removeEmbeddedForeignKey
|
772
|
+
@param {DS.Model} record
|
773
|
+
@param {DS.Model} embeddedRecord
|
774
|
+
@param {Object} relationship
|
775
|
+
@param {Object} json
|
776
|
+
*/
|
777
|
+
removeEmbeddedForeignKey: function (record, embeddedRecord, relationship, json) {
|
778
|
+
if (relationship.kind === 'hasMany') {
|
779
|
+
return;
|
780
|
+
} else if (relationship.kind === 'belongsTo') {
|
781
|
+
var parentRecord = record.constructor.inverseFor(relationship.key);
|
782
|
+
if (parentRecord) {
|
783
|
+
var name = parentRecord.name;
|
784
|
+
var embeddedSerializer = this.store.serializerFor(embeddedRecord.constructor);
|
785
|
+
var parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind);
|
786
|
+
if (parentKey) {
|
787
|
+
delete json[parentKey];
|
788
|
+
}
|
789
|
+
}
|
506
790
|
}
|
507
791
|
},
|
508
792
|
|
509
793
|
/**
|
510
|
-
Extract embedded
|
511
|
-
and add
|
794
|
+
Extract an embedded object from the payload for a single object
|
795
|
+
and add the object in the compound document (side-loaded) format instead.
|
796
|
+
|
797
|
+
A payload with an attribute configured for embedded records needs to be extracted:
|
798
|
+
|
799
|
+
```js
|
800
|
+
{
|
801
|
+
"post": {
|
802
|
+
"id": 1
|
803
|
+
"title": "Rails is omakase",
|
804
|
+
"author": {
|
805
|
+
"id": 2
|
806
|
+
"name": "dhh"
|
807
|
+
}
|
808
|
+
"comments": []
|
809
|
+
}
|
810
|
+
}
|
811
|
+
```
|
812
|
+
|
813
|
+
Ember Data is expecting a payload with a compound document (side-loaded) like:
|
814
|
+
|
815
|
+
```js
|
816
|
+
{
|
817
|
+
"post": {
|
818
|
+
"id": "1"
|
819
|
+
"title": "Rails is omakase",
|
820
|
+
"author": "2"
|
821
|
+
"comments": []
|
822
|
+
},
|
823
|
+
"authors": [{
|
824
|
+
"id": "2"
|
825
|
+
"post": "1"
|
826
|
+
"name": "dhh"
|
827
|
+
}]
|
828
|
+
"comments": []
|
829
|
+
}
|
830
|
+
```
|
831
|
+
|
832
|
+
The payload's `author` attribute represents an object with a `belongsTo` relationship.
|
833
|
+
The `post` attribute under `author` is the foreign key with the id for the post
|
512
834
|
|
513
835
|
@method extractSingle
|
836
|
+
@param {DS.Store} store
|
837
|
+
@param {subclass of DS.Model} primaryType
|
838
|
+
@param {Object} payload
|
839
|
+
@param {String} recordId
|
840
|
+
@return Object the primary response to the original request
|
514
841
|
*/
|
515
|
-
extractSingle: function(store, primaryType, payload, recordId
|
842
|
+
extractSingle: function(store, primaryType, payload, recordId) {
|
516
843
|
var root = this.keyForAttribute(primaryType.typeKey),
|
517
844
|
partial = payload[root];
|
518
845
|
|
519
|
-
updatePayloadWithEmbedded(
|
846
|
+
updatePayloadWithEmbedded(this, store, primaryType, payload, partial);
|
520
847
|
|
521
|
-
return this._super(store, primaryType, payload, recordId
|
848
|
+
return this._super(store, primaryType, payload, recordId);
|
522
849
|
},
|
523
850
|
|
524
851
|
/**
|
525
|
-
Extract embedded objects
|
526
|
-
and add them as
|
852
|
+
Extract embedded objects in an array when an attr is configured for embedded,
|
853
|
+
and add them as side-loaded objects instead.
|
854
|
+
|
855
|
+
A payload with an attr configured for embedded records needs to be extracted:
|
856
|
+
|
857
|
+
```js
|
858
|
+
{
|
859
|
+
"post": {
|
860
|
+
"id": "1"
|
861
|
+
"title": "Rails is omakase",
|
862
|
+
"comments": [{
|
863
|
+
"id": "1",
|
864
|
+
"body": "Rails is unagi"
|
865
|
+
}, {
|
866
|
+
"id": "2",
|
867
|
+
"body": "Omakase O_o"
|
868
|
+
}]
|
869
|
+
}
|
870
|
+
}
|
871
|
+
```
|
872
|
+
|
873
|
+
Ember Data is expecting a payload with compound document (side-loaded) like:
|
874
|
+
|
875
|
+
```js
|
876
|
+
{
|
877
|
+
"post": {
|
878
|
+
"id": "1"
|
879
|
+
"title": "Rails is omakase",
|
880
|
+
"comments": ["1", "2"]
|
881
|
+
},
|
882
|
+
"comments": [{
|
883
|
+
"id": "1",
|
884
|
+
"body": "Rails is unagi"
|
885
|
+
}, {
|
886
|
+
"id": "2",
|
887
|
+
"body": "Omakase O_o"
|
888
|
+
}]
|
889
|
+
}
|
890
|
+
```
|
891
|
+
|
892
|
+
The payload's `comments` attribute represents records in a `hasMany` relationship
|
527
893
|
|
528
894
|
@method extractArray
|
895
|
+
@param {DS.Store} store
|
896
|
+
@param {subclass of DS.Model} primaryType
|
897
|
+
@param {Object} payload
|
898
|
+
@return {Array<Object>} The primary array that was returned in response
|
899
|
+
to the original query.
|
529
900
|
*/
|
530
|
-
extractArray: function(store,
|
531
|
-
var root = this.keyForAttribute(
|
901
|
+
extractArray: function(store, primaryType, payload) {
|
902
|
+
var root = this.keyForAttribute(primaryType.typeKey),
|
532
903
|
partials = payload[pluralize(root)];
|
533
904
|
|
534
905
|
forEach(partials, function(partial) {
|
535
|
-
updatePayloadWithEmbedded(store,
|
906
|
+
updatePayloadWithEmbedded(this, store, primaryType, payload, partial);
|
536
907
|
}, this);
|
537
908
|
|
538
|
-
return this._super(store,
|
909
|
+
return this._super(store, primaryType, payload);
|
539
910
|
}
|
540
911
|
});
|
541
912
|
|
542
|
-
|
913
|
+
// checks config for attrs option to embedded (always) - serialize and deserialize
|
914
|
+
function hasEmbeddedAlwaysOption(attrs, attr) {
|
915
|
+
var option = attrsOption(attrs, attr);
|
916
|
+
return option && option.embedded === 'always';
|
917
|
+
}
|
918
|
+
|
919
|
+
// checks config for attrs option to serialize ids
|
920
|
+
function hasSerializeRecordsOption(attrs, attr) {
|
921
|
+
var alwaysEmbed = hasEmbeddedAlwaysOption(attrs, attr);
|
922
|
+
var option = attrsOption(attrs, attr);
|
923
|
+
return alwaysEmbed || (option && (option.serialize === 'records'));
|
924
|
+
}
|
925
|
+
|
926
|
+
// checks config for attrs option to serialize records
|
927
|
+
function hasSerializeIdsOption(attrs, attr) {
|
928
|
+
var option = attrsOption(attrs, attr);
|
929
|
+
return option && (option.serialize === 'ids' || option.serialize === 'id');
|
930
|
+
}
|
931
|
+
|
932
|
+
// checks config for attrs option to serialize records
|
933
|
+
function noSerializeOptionSpecified(attrs, attr) {
|
934
|
+
var option = attrsOption(attrs, attr);
|
935
|
+
var serializeRecords = hasSerializeRecordsOption(attrs, attr);
|
936
|
+
var serializeIds = hasSerializeIdsOption(attrs, attr);
|
937
|
+
return !(option && (option.serialize || option.embedded));
|
938
|
+
}
|
939
|
+
|
940
|
+
// checks config for attrs option to deserialize records
|
941
|
+
// a defined option object for a resource is treated the same as
|
942
|
+
// `deserialize: 'records'`
|
943
|
+
function hasDeserializeRecordsOption(attrs, attr) {
|
944
|
+
var alwaysEmbed = hasEmbeddedAlwaysOption(attrs, attr);
|
945
|
+
var option = attrsOption(attrs, attr);
|
946
|
+
var hasSerializingOption = option && (option.deserialize || option.serialize);
|
947
|
+
return alwaysEmbed || hasSerializingOption /* option.deserialize === 'records' */;
|
948
|
+
}
|
949
|
+
|
950
|
+
function attrsOption(attrs, attr) {
|
951
|
+
return attrs && (attrs[Ember.String.camelize(attr)] || attrs[attr]);
|
952
|
+
}
|
953
|
+
|
954
|
+
// chooses a relationship kind to branch which function is used to update payload
|
955
|
+
// does not change payload if attr is not embedded
|
956
|
+
function updatePayloadWithEmbedded(serializer, store, type, payload, partial) {
|
543
957
|
var attrs = get(serializer, 'attrs');
|
544
958
|
|
545
959
|
if (!attrs) {
|
546
960
|
return;
|
547
961
|
}
|
548
|
-
|
549
962
|
type.eachRelationship(function(key, relationship) {
|
550
|
-
|
551
|
-
|
552
|
-
serializer
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
963
|
+
if (hasDeserializeRecordsOption(attrs, key)) {
|
964
|
+
if (relationship.kind === "hasMany") {
|
965
|
+
updatePayloadWithEmbeddedHasMany(serializer, store, key, relationship, payload, partial);
|
966
|
+
}
|
967
|
+
if (relationship.kind === "belongsTo") {
|
968
|
+
updatePayloadWithEmbeddedBelongsTo(serializer, store, key, relationship, payload, partial);
|
969
|
+
}
|
557
970
|
}
|
971
|
+
});
|
972
|
+
}
|
558
973
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
974
|
+
// handles embedding for `hasMany` relationship
|
975
|
+
function updatePayloadWithEmbeddedHasMany(serializer, store, primaryType, relationship, payload, partial) {
|
976
|
+
var embeddedSerializer = store.serializerFor(relationship.type.typeKey);
|
977
|
+
var primaryKey = get(serializer, 'primaryKey');
|
978
|
+
var attr = relationship.type.typeKey;
|
979
|
+
// underscore forces the embedded records to be side loaded.
|
980
|
+
// it is needed when main type === relationship.type
|
981
|
+
var embeddedTypeKey = '_' + serializer.typeForRoot(relationship.type.typeKey);
|
982
|
+
var expandedKey = serializer.keyForRelationship(primaryType, relationship.kind);
|
983
|
+
var attribute = serializer.keyForAttribute(primaryType);
|
984
|
+
var ids = [];
|
985
|
+
|
986
|
+
if (!partial[attribute]) {
|
987
|
+
return;
|
988
|
+
}
|
566
989
|
|
567
|
-
|
568
|
-
return;
|
569
|
-
}
|
990
|
+
payload[embeddedTypeKey] = payload[embeddedTypeKey] || [];
|
570
991
|
|
571
|
-
|
992
|
+
forEach(partial[attribute], function(data) {
|
993
|
+
var embeddedType = store.modelFor(attr);
|
994
|
+
updatePayloadWithEmbedded(embeddedSerializer, store, embeddedType, payload, data);
|
995
|
+
ids.push(data[primaryKey]);
|
996
|
+
payload[embeddedTypeKey].push(data);
|
997
|
+
});
|
572
998
|
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
ids.push(data[primaryKey]);
|
577
|
-
payload[embeddedTypeKey].push(data);
|
578
|
-
});
|
999
|
+
partial[expandedKey] = ids;
|
1000
|
+
delete partial[attribute];
|
1001
|
+
}
|
579
1002
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
1003
|
+
// handles embedding for `belongsTo` relationship
|
1004
|
+
function updatePayloadWithEmbeddedBelongsTo(serializer, store, primaryType, relationship, payload, partial) {
|
1005
|
+
var attrs = serializer.get('attrs');
|
1006
|
+
|
1007
|
+
if (!attrs ||
|
1008
|
+
!(hasDeserializeRecordsOption(attrs, Ember.String.camelize(primaryType)) ||
|
1009
|
+
hasDeserializeRecordsOption(attrs, primaryType))) {
|
1010
|
+
return;
|
1011
|
+
}
|
1012
|
+
var attr = relationship.type.typeKey;
|
1013
|
+
var _serializer = store.serializerFor(relationship.type.typeKey);
|
1014
|
+
var primaryKey = get(_serializer, 'primaryKey');
|
1015
|
+
var embeddedTypeKey = Ember.String.pluralize(attr); // TODO don't use pluralize
|
1016
|
+
var expandedKey = _serializer.keyForRelationship(primaryType, relationship.kind);
|
1017
|
+
var attribute = _serializer.keyForAttribute(primaryType);
|
1018
|
+
|
1019
|
+
if (!partial[attribute]) {
|
1020
|
+
return;
|
1021
|
+
}
|
1022
|
+
payload[embeddedTypeKey] = payload[embeddedTypeKey] || [];
|
1023
|
+
var embeddedType = store.modelFor(relationship.type.typeKey);
|
1024
|
+
// Recursive call for nested record
|
1025
|
+
updatePayloadWithEmbedded(_serializer, store, embeddedType, payload, partial[attribute]);
|
1026
|
+
partial[expandedKey] = partial[attribute].id;
|
1027
|
+
// Need to move an embedded `belongsTo` object into a pluralized collection
|
1028
|
+
payload[embeddedTypeKey].push(partial[attribute]);
|
1029
|
+
// Need a reference to the parent so relationship works between both `belongsTo` records
|
1030
|
+
partial[attribute][relationship.parentType.typeKey + '_id'] = partial.id;
|
1031
|
+
delete partial[attribute];
|
584
1032
|
}
|
585
1033
|
|
586
1034
|
__exports__["default"] = EmbeddedRecordsMixin;
|
@@ -616,11 +1064,11 @@ define("ember-data/lib/adapters/fixture_adapter",
|
|
616
1064
|
|
617
1065
|
/**
|
618
1066
|
`DS.FixtureAdapter` is an adapter that loads records from memory.
|
619
|
-
|
1067
|
+
It's primarily used for development and testing. You can also use
|
620
1068
|
`DS.FixtureAdapter` while working on the API but are not ready to
|
621
1069
|
integrate yet. It is a fully functioning adapter. All CRUD methods
|
622
1070
|
are implemented. You can also implement query logic that a remote
|
623
|
-
system would do.
|
1071
|
+
system would do. It's possible to develop your entire application
|
624
1072
|
with `DS.FixtureAdapter`.
|
625
1073
|
|
626
1074
|
For information on how to use the `FixtureAdapter` in your
|
@@ -1039,11 +1487,13 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1039
1487
|
|
1040
1488
|
### Headers customization
|
1041
1489
|
|
1042
|
-
Some APIs require HTTP headers, e.g. to provide an API key.
|
1043
|
-
headers can be
|
1490
|
+
Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary
|
1491
|
+
headers can be set as key/value pairs on the `RESTAdapter`'s `headers`
|
1492
|
+
object and Ember Data will send them along with each ajax request.
|
1493
|
+
|
1044
1494
|
|
1045
1495
|
```js
|
1046
|
-
DS.RESTAdapter.
|
1496
|
+
App.ApplicationAdapter = DS.RESTAdapter.extend({
|
1047
1497
|
headers: {
|
1048
1498
|
"API_KEY": "secret key",
|
1049
1499
|
"ANOTHER_HEADER": "Some header value"
|
@@ -1051,6 +1501,39 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1051
1501
|
});
|
1052
1502
|
```
|
1053
1503
|
|
1504
|
+
`headers` can also be used as a computed property to support dynamic
|
1505
|
+
headers. In the example below, the `session` object has been
|
1506
|
+
injected into an adapter by Ember's container.
|
1507
|
+
|
1508
|
+
```js
|
1509
|
+
App.ApplicationAdapter = DS.RESTAdapter.extend({
|
1510
|
+
headers: function() {
|
1511
|
+
return {
|
1512
|
+
"API_KEY": this.get("session.authToken"),
|
1513
|
+
"ANOTHER_HEADER": "Some header value"
|
1514
|
+
};
|
1515
|
+
}.property("session.authToken")
|
1516
|
+
});
|
1517
|
+
```
|
1518
|
+
|
1519
|
+
In some cases, your dynamic headers may require data from some
|
1520
|
+
object outside of Ember's observer system (for example
|
1521
|
+
`document.cookie`). You can use the
|
1522
|
+
[volatile](/api/classes/Ember.ComputedProperty.html#method_volatile)
|
1523
|
+
function to set the property into a non-chached mode causing the headers to
|
1524
|
+
be recomputed with every request.
|
1525
|
+
|
1526
|
+
```js
|
1527
|
+
App.ApplicationAdapter = DS.RESTAdapter.extend({
|
1528
|
+
headers: function() {
|
1529
|
+
return {
|
1530
|
+
"API_KEY": Ember.get(document.cookie.match(/apiKey\=([^;]*)/), "1"),
|
1531
|
+
"ANOTHER_HEADER": "Some header value"
|
1532
|
+
};
|
1533
|
+
}.property().volatile();
|
1534
|
+
});
|
1535
|
+
```
|
1536
|
+
|
1054
1537
|
@class RESTAdapter
|
1055
1538
|
@constructor
|
1056
1539
|
@namespace DS
|
@@ -1090,11 +1573,14 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1090
1573
|
*/
|
1091
1574
|
|
1092
1575
|
/**
|
1093
|
-
Some APIs require HTTP headers, e.g. to provide an API
|
1094
|
-
headers can be
|
1576
|
+
Some APIs require HTTP headers, e.g. to provide an API
|
1577
|
+
key. Arbitrary headers can be set as key/value pairs on the
|
1578
|
+
`RESTAdapter`'s `headers` object and Ember Data will send them
|
1579
|
+
along with each ajax request. For dynamic headers see [headers
|
1580
|
+
customization](/api/data/classes/DS.RESTAdapter.html#toc_headers-customization).
|
1095
1581
|
|
1096
1582
|
```javascript
|
1097
|
-
DS.RESTAdapter.
|
1583
|
+
App.ApplicationAdapter = DS.RESTAdapter.extend({
|
1098
1584
|
headers: {
|
1099
1585
|
"API_KEY": "secret key",
|
1100
1586
|
"ANOTHER_HEADER": "Some header value"
|
@@ -1119,7 +1605,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1119
1605
|
@param {DS.Store} store
|
1120
1606
|
@param {subclass of DS.Model} type
|
1121
1607
|
@param {String} id
|
1122
|
-
@
|
1608
|
+
@return {Promise} promise
|
1123
1609
|
*/
|
1124
1610
|
find: function(store, type, id) {
|
1125
1611
|
return this.ajax(this.buildURL(type.typeKey, id), 'GET');
|
@@ -1137,7 +1623,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1137
1623
|
@param {DS.Store} store
|
1138
1624
|
@param {subclass of DS.Model} type
|
1139
1625
|
@param {String} sinceToken
|
1140
|
-
@
|
1626
|
+
@return {Promise} promise
|
1141
1627
|
*/
|
1142
1628
|
findAll: function(store, type, sinceToken) {
|
1143
1629
|
var query;
|
@@ -1164,7 +1650,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1164
1650
|
@param {DS.Store} store
|
1165
1651
|
@param {subclass of DS.Model} type
|
1166
1652
|
@param {Object} query
|
1167
|
-
@
|
1653
|
+
@return {Promise} promise
|
1168
1654
|
*/
|
1169
1655
|
findQuery: function(store, type, query) {
|
1170
1656
|
return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query });
|
@@ -1202,7 +1688,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1202
1688
|
@param {DS.Store} store
|
1203
1689
|
@param {subclass of DS.Model} type
|
1204
1690
|
@param {Array} ids
|
1205
|
-
@
|
1691
|
+
@return {Promise} promise
|
1206
1692
|
*/
|
1207
1693
|
findMany: function(store, type, ids) {
|
1208
1694
|
return this.ajax(this.buildURL(type.typeKey), 'GET', { data: { ids: ids } });
|
@@ -1235,7 +1721,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1235
1721
|
@param {DS.Store} store
|
1236
1722
|
@param {DS.Model} record
|
1237
1723
|
@param {String} url
|
1238
|
-
@
|
1724
|
+
@return {Promise} promise
|
1239
1725
|
*/
|
1240
1726
|
findHasMany: function(store, record, url) {
|
1241
1727
|
var host = get(this, 'host'),
|
@@ -1274,7 +1760,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1274
1760
|
@param {DS.Store} store
|
1275
1761
|
@param {DS.Model} record
|
1276
1762
|
@param {String} url
|
1277
|
-
@
|
1763
|
+
@return {Promise} promise
|
1278
1764
|
*/
|
1279
1765
|
findBelongsTo: function(store, record, url) {
|
1280
1766
|
var id = get(record, 'id'),
|
@@ -1297,7 +1783,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1297
1783
|
@param {DS.Store} store
|
1298
1784
|
@param {subclass of DS.Model} type
|
1299
1785
|
@param {DS.Model} record
|
1300
|
-
@
|
1786
|
+
@return {Promise} promise
|
1301
1787
|
*/
|
1302
1788
|
createRecord: function(store, type, record) {
|
1303
1789
|
var data = {};
|
@@ -1322,7 +1808,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1322
1808
|
@param {DS.Store} store
|
1323
1809
|
@param {subclass of DS.Model} type
|
1324
1810
|
@param {DS.Model} record
|
1325
|
-
@
|
1811
|
+
@return {Promise} promise
|
1326
1812
|
*/
|
1327
1813
|
updateRecord: function(store, type, record) {
|
1328
1814
|
var data = {};
|
@@ -1344,7 +1830,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1344
1830
|
@param {DS.Store} store
|
1345
1831
|
@param {subclass of DS.Model} type
|
1346
1832
|
@param {DS.Model} record
|
1347
|
-
@
|
1833
|
+
@return {Promise} promise
|
1348
1834
|
*/
|
1349
1835
|
deleteRecord: function(store, type, record) {
|
1350
1836
|
var id = get(record, 'id');
|
@@ -1365,7 +1851,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1365
1851
|
@method buildURL
|
1366
1852
|
@param {String} type
|
1367
1853
|
@param {String} id
|
1368
|
-
@
|
1854
|
+
@return {String} url
|
1369
1855
|
*/
|
1370
1856
|
buildURL: function(type, id) {
|
1371
1857
|
var url = [],
|
@@ -1430,17 +1916,17 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1430
1916
|
endpoint of "/line_items/".
|
1431
1917
|
|
1432
1918
|
```js
|
1433
|
-
DS.RESTAdapter.
|
1919
|
+
App.ApplicationAdapter = DS.RESTAdapter.extend({
|
1434
1920
|
pathForType: function(type) {
|
1435
1921
|
var decamelized = Ember.String.decamelize(type);
|
1436
1922
|
return Ember.String.pluralize(decamelized);
|
1437
|
-
}
|
1923
|
+
}
|
1438
1924
|
});
|
1439
1925
|
```
|
1440
1926
|
|
1441
1927
|
@method pathForType
|
1442
1928
|
@param {String} type
|
1443
|
-
@
|
1929
|
+
@return {String} path
|
1444
1930
|
**/
|
1445
1931
|
pathForType: function(type) {
|
1446
1932
|
var camelized = Ember.String.camelize(type);
|
@@ -1482,7 +1968,7 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1482
1968
|
@return {Object} jqXHR
|
1483
1969
|
*/
|
1484
1970
|
ajaxError: function(jqXHR) {
|
1485
|
-
if (jqXHR) {
|
1971
|
+
if (jqXHR && typeof jqXHR === 'object') {
|
1486
1972
|
jqXHR.then = null;
|
1487
1973
|
}
|
1488
1974
|
|
@@ -1551,8 +2037,8 @@ define("ember-data/lib/adapters/rest_adapter",
|
|
1551
2037
|
hash.data = JSON.stringify(hash.data);
|
1552
2038
|
}
|
1553
2039
|
|
1554
|
-
|
1555
|
-
|
2040
|
+
var headers = get(this, 'headers');
|
2041
|
+
if (headers !== undefined) {
|
1556
2042
|
hash.beforeSend = function (xhr) {
|
1557
2043
|
forEach.call(Ember.keys(headers), function(key) {
|
1558
2044
|
xhr.setRequestHeader(key, headers[key]);
|
@@ -1587,17 +2073,13 @@ define("ember-data/lib/core",
|
|
1587
2073
|
/**
|
1588
2074
|
@property VERSION
|
1589
2075
|
@type String
|
1590
|
-
@default '1.0.0-beta.
|
2076
|
+
@default '1.0.0-beta.8.2a68c63a'
|
1591
2077
|
@static
|
1592
2078
|
*/
|
1593
2079
|
DS = Ember.Namespace.create({
|
1594
|
-
VERSION: '1.0.0-beta.
|
2080
|
+
VERSION: '1.0.0-beta.8.2a68c63a'
|
1595
2081
|
});
|
1596
2082
|
|
1597
|
-
if ('undefined' !== typeof window) {
|
1598
|
-
window.DS = DS;
|
1599
|
-
}
|
1600
|
-
|
1601
2083
|
if (Ember.libraries) {
|
1602
2084
|
Ember.libraries.registerCoreLibrary('Ember Data', DS.VERSION);
|
1603
2085
|
}
|
@@ -1605,6 +2087,90 @@ define("ember-data/lib/core",
|
|
1605
2087
|
|
1606
2088
|
__exports__["default"] = DS;
|
1607
2089
|
});
|
2090
|
+
define("ember-data/lib/ember-initializer",
|
2091
|
+
["./setup-container"],
|
2092
|
+
function(__dependency1__) {
|
2093
|
+
"use strict";
|
2094
|
+
var setupContainer = __dependency1__["default"];
|
2095
|
+
|
2096
|
+
var K = Ember.K;
|
2097
|
+
|
2098
|
+
/**
|
2099
|
+
@module ember-data
|
2100
|
+
*/
|
2101
|
+
|
2102
|
+
/**
|
2103
|
+
|
2104
|
+
This code initializes Ember-Data onto an Ember application.
|
2105
|
+
|
2106
|
+
If an Ember.js developer defines a subclass of DS.Store on their application,
|
2107
|
+
as `App.ApplicationStore` (or via a module system that resolves to `store:application`)
|
2108
|
+
this code will automatically instantiate it and make it available on the
|
2109
|
+
router.
|
2110
|
+
|
2111
|
+
Additionally, after an application's controllers have been injected, they will
|
2112
|
+
each have the store made available to them.
|
2113
|
+
|
2114
|
+
For example, imagine an Ember.js application with the following classes:
|
2115
|
+
|
2116
|
+
App.ApplicationStore = DS.Store.extend({
|
2117
|
+
adapter: 'custom'
|
2118
|
+
});
|
2119
|
+
|
2120
|
+
App.PostsController = Ember.ArrayController.extend({
|
2121
|
+
// ...
|
2122
|
+
});
|
2123
|
+
|
2124
|
+
When the application is initialized, `App.ApplicationStore` will automatically be
|
2125
|
+
instantiated, and the instance of `App.PostsController` will have its `store`
|
2126
|
+
property set to that instance.
|
2127
|
+
|
2128
|
+
Note that this code will only be run if the `ember-application` package is
|
2129
|
+
loaded. If Ember Data is being used in an environment other than a
|
2130
|
+
typical application (e.g., node.js where only `ember-runtime` is available),
|
2131
|
+
this code will be ignored.
|
2132
|
+
*/
|
2133
|
+
|
2134
|
+
Ember.onLoad('Ember.Application', function(Application) {
|
2135
|
+
|
2136
|
+
Application.initializer({
|
2137
|
+
name: "ember-data",
|
2138
|
+
initialize: setupContainer
|
2139
|
+
});
|
2140
|
+
|
2141
|
+
// Deprecated initializers to satisfy old code that depended on them
|
2142
|
+
|
2143
|
+
Application.initializer({
|
2144
|
+
name: "store",
|
2145
|
+
after: "ember-data",
|
2146
|
+
initialize: K
|
2147
|
+
});
|
2148
|
+
|
2149
|
+
Application.initializer({
|
2150
|
+
name: "activeModelAdapter",
|
2151
|
+
before: "store",
|
2152
|
+
initialize: K
|
2153
|
+
});
|
2154
|
+
|
2155
|
+
Application.initializer({
|
2156
|
+
name: "transforms",
|
2157
|
+
before: "store",
|
2158
|
+
initialize: K
|
2159
|
+
});
|
2160
|
+
|
2161
|
+
Application.initializer({
|
2162
|
+
name: "data-adapter",
|
2163
|
+
before: "store",
|
2164
|
+
initialize: K
|
2165
|
+
});
|
2166
|
+
|
2167
|
+
Application.initializer({
|
2168
|
+
name: "injectStore",
|
2169
|
+
before: "store",
|
2170
|
+
initialize: K
|
2171
|
+
});
|
2172
|
+
});
|
2173
|
+
});
|
1608
2174
|
define("ember-data/lib/ext/date",
|
1609
2175
|
[],
|
1610
2176
|
function() {
|
@@ -1670,122 +2236,110 @@ define("ember-data/lib/ext/date",
|
|
1670
2236
|
Date.parse = Ember.Date.parse;
|
1671
2237
|
}
|
1672
2238
|
});
|
1673
|
-
define("ember-data/lib/initializers",
|
1674
|
-
["
|
1675
|
-
function(__dependency1__,
|
2239
|
+
define("ember-data/lib/initializers/data_adapter",
|
2240
|
+
["../system/debug/debug_adapter","exports"],
|
2241
|
+
function(__dependency1__, __exports__) {
|
1676
2242
|
"use strict";
|
1677
|
-
var
|
1678
|
-
var JSONSerializer = __dependency2__.JSONSerializer;
|
1679
|
-
var RESTSerializer = __dependency2__.RESTSerializer;
|
1680
|
-
var RESTAdapter = __dependency3__.RESTAdapter;
|
1681
|
-
var DebugAdapter = __dependency4__["default"];
|
1682
|
-
var ContainerProxy = __dependency5__["default"];
|
1683
|
-
var BooleanTransform = __dependency6__.BooleanTransform;
|
1684
|
-
var DateTransform = __dependency6__.DateTransform;
|
1685
|
-
var StringTransform = __dependency6__.StringTransform;
|
1686
|
-
var NumberTransform = __dependency6__.NumberTransform;
|
2243
|
+
var DebugAdapter = __dependency1__["default"];
|
1687
2244
|
|
1688
2245
|
/**
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
var set = Ember.set;
|
1693
|
-
|
1694
|
-
/*
|
1695
|
-
This code registers an injection for Ember.Application.
|
1696
|
-
|
1697
|
-
If an Ember.js developer defines a subclass of DS.Store on their application,
|
1698
|
-
this code will automatically instantiate it and make it available on the
|
1699
|
-
router.
|
1700
|
-
|
1701
|
-
Additionally, after an application's controllers have been injected, they will
|
1702
|
-
each have the store made available to them.
|
1703
|
-
|
1704
|
-
For example, imagine an Ember.js application with the following classes:
|
1705
|
-
|
1706
|
-
App.Store = DS.Store.extend({
|
1707
|
-
adapter: 'custom'
|
1708
|
-
});
|
1709
|
-
|
1710
|
-
App.PostsController = Ember.ArrayController.extend({
|
1711
|
-
// ...
|
1712
|
-
});
|
2246
|
+
Configures a container with injections on Ember applications
|
2247
|
+
for the Ember-Data store. Accepts an optional namespace argument.
|
1713
2248
|
|
1714
|
-
|
1715
|
-
|
1716
|
-
property set to that instance.
|
1717
|
-
|
1718
|
-
Note that this code will only be run if the `ember-application` package is
|
1719
|
-
loaded. If Ember Data is being used in an environment other than a
|
1720
|
-
typical application (e.g., node.js where only `ember-runtime` is available),
|
1721
|
-
this code will be ignored.
|
2249
|
+
@method initializeStoreInjections
|
2250
|
+
@param {Ember.Container} container
|
1722
2251
|
*/
|
2252
|
+
__exports__["default"] = function initializeDebugAdapter(container){
|
2253
|
+
container.register('data-adapter:main', DebugAdapter);
|
2254
|
+
};
|
2255
|
+
});
|
2256
|
+
define("ember-data/lib/initializers/store",
|
2257
|
+
["../serializers","../adapters","../system/container_proxy","../system/store","exports"],
|
2258
|
+
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) {
|
2259
|
+
"use strict";
|
2260
|
+
var JSONSerializer = __dependency1__.JSONSerializer;
|
2261
|
+
var RESTSerializer = __dependency1__.RESTSerializer;
|
2262
|
+
var RESTAdapter = __dependency2__.RESTAdapter;
|
2263
|
+
var ContainerProxy = __dependency3__["default"];
|
2264
|
+
var Store = __dependency4__["default"];
|
1723
2265
|
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
initialize: function(container, application) {
|
1729
|
-
application.register('store:main', application.Store || Store);
|
1730
|
-
|
1731
|
-
// allow older names to be looked up
|
1732
|
-
|
1733
|
-
var proxy = new ContainerProxy(container);
|
1734
|
-
proxy.registerDeprecations([
|
1735
|
-
{deprecated: 'serializer:_default', valid: 'serializer:-default'},
|
1736
|
-
{deprecated: 'serializer:_rest', valid: 'serializer:-rest'},
|
1737
|
-
{deprecated: 'adapter:_rest', valid: 'adapter:-rest'}
|
1738
|
-
]);
|
2266
|
+
/**
|
2267
|
+
Configures a container for use with an Ember-Data
|
2268
|
+
store. Accepts an optional namespace argument.
|
1739
2269
|
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
2270
|
+
@method initializeStore
|
2271
|
+
@param {Ember.Container} container
|
2272
|
+
@param {Object} [application] an application namespace
|
2273
|
+
*/
|
2274
|
+
__exports__["default"] = function initializeStore(container, application){
|
2275
|
+
Ember.deprecate('Specifying a custom Store for Ember Data on your global namespace as `App.Store` ' +
|
2276
|
+
'has been deprecated. Please use `App.ApplicationStore` instead.', !(application && application.Store));
|
1744
2277
|
|
1745
|
-
|
1746
|
-
// TODO: Do this in a finisher hook
|
1747
|
-
container.lookup('store:main');
|
1748
|
-
}
|
1749
|
-
});
|
2278
|
+
container.register('store:main', container.lookupFactory('store:application') || (application && application.Store) || Store);
|
1750
2279
|
|
1751
|
-
|
1752
|
-
name: "transforms",
|
1753
|
-
before: "store",
|
2280
|
+
// allow older names to be looked up
|
1754
2281
|
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
});
|
2282
|
+
var proxy = new ContainerProxy(container);
|
2283
|
+
proxy.registerDeprecations([
|
2284
|
+
{deprecated: 'serializer:_default', valid: 'serializer:-default'},
|
2285
|
+
{deprecated: 'serializer:_rest', valid: 'serializer:-rest'},
|
2286
|
+
{deprecated: 'adapter:_rest', valid: 'adapter:-rest'}
|
2287
|
+
]);
|
1762
2288
|
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
2289
|
+
// new go forward paths
|
2290
|
+
container.register('serializer:-default', JSONSerializer);
|
2291
|
+
container.register('serializer:-rest', RESTSerializer);
|
2292
|
+
container.register('adapter:-rest', RESTAdapter);
|
1766
2293
|
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
2294
|
+
// Eagerly generate the store so defaultStore is populated.
|
2295
|
+
// TODO: Do this in a finisher hook
|
2296
|
+
container.lookup('store:main');
|
2297
|
+
};
|
2298
|
+
});
|
2299
|
+
define("ember-data/lib/initializers/store_injections",
|
2300
|
+
["exports"],
|
2301
|
+
function(__exports__) {
|
2302
|
+
"use strict";
|
2303
|
+
/**
|
2304
|
+
Configures a container with injections on Ember applications
|
2305
|
+
for the Ember-Data store. Accepts an optional namespace argument.
|
1771
2306
|
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
2307
|
+
@method initializeStoreInjections
|
2308
|
+
@param {Ember.Container} container
|
2309
|
+
*/
|
2310
|
+
__exports__["default"] = function initializeStoreInjections(container){
|
2311
|
+
container.injection('controller', 'store', 'store:main');
|
2312
|
+
container.injection('route', 'store', 'store:main');
|
2313
|
+
container.injection('serializer', 'store', 'store:main');
|
2314
|
+
container.injection('data-adapter', 'store', 'store:main');
|
2315
|
+
};
|
2316
|
+
});
|
2317
|
+
define("ember-data/lib/initializers/transforms",
|
2318
|
+
["../transforms","exports"],
|
2319
|
+
function(__dependency1__, __exports__) {
|
2320
|
+
"use strict";
|
2321
|
+
var BooleanTransform = __dependency1__.BooleanTransform;
|
2322
|
+
var DateTransform = __dependency1__.DateTransform;
|
2323
|
+
var StringTransform = __dependency1__.StringTransform;
|
2324
|
+
var NumberTransform = __dependency1__.NumberTransform;
|
1775
2325
|
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
application.inject('serializer', 'store', 'store:main');
|
1780
|
-
application.inject('data-adapter', 'store', 'store:main');
|
1781
|
-
}
|
1782
|
-
});
|
2326
|
+
/**
|
2327
|
+
Configures a container for use with Ember-Data
|
2328
|
+
transforms.
|
1783
2329
|
|
1784
|
-
|
2330
|
+
@method initializeTransforms
|
2331
|
+
@param {Ember.Container} container
|
2332
|
+
*/
|
2333
|
+
__exports__["default"] = function initializeTransforms(container){
|
2334
|
+
container.register('transform:boolean', BooleanTransform);
|
2335
|
+
container.register('transform:date', DateTransform);
|
2336
|
+
container.register('transform:number', NumberTransform);
|
2337
|
+
container.register('transform:string', StringTransform);
|
2338
|
+
};
|
1785
2339
|
});
|
1786
2340
|
define("ember-data/lib/main",
|
1787
|
-
["./core","./ext/date","./system/store","./system/model","./system/changes","./system/adapter","./system/debug","./system/record_arrays","./system/record_array_manager","./adapters","./serializers/json_serializer","./serializers/rest_serializer","../../ember-inflector/lib/main","../../activemodel-adapter/lib/main","./transforms","./system/relationships","./
|
1788
|
-
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __dependency14__, __dependency15__, __dependency16__, __dependency17__, __dependency18__, __exports__) {
|
2341
|
+
["./core","./ext/date","./system/store","./system/model","./system/changes","./system/adapter","./system/debug","./system/record_arrays","./system/record_array_manager","./adapters","./serializers/json_serializer","./serializers/rest_serializer","../../ember-inflector/lib/main","../../activemodel-adapter/lib/main","./transforms","./system/relationships","./ember-initializer","./setup-container","./system/container_proxy","exports"],
|
2342
|
+
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __dependency14__, __dependency15__, __dependency16__, __dependency17__, __dependency18__, __dependency19__, __exports__) {
|
1789
2343
|
"use strict";
|
1790
2344
|
/**
|
1791
2345
|
Ember Data
|
@@ -1838,8 +2392,9 @@ define("ember-data/lib/main",
|
|
1838
2392
|
|
1839
2393
|
var hasMany = __dependency16__.hasMany;
|
1840
2394
|
var belongsTo = __dependency16__.belongsTo;
|
2395
|
+
var setupContainer = __dependency18__["default"];
|
1841
2396
|
|
1842
|
-
var ContainerProxy =
|
2397
|
+
var ContainerProxy = __dependency19__["default"];
|
1843
2398
|
|
1844
2399
|
DS.Store = Store;
|
1845
2400
|
DS.PromiseArray = PromiseArray;
|
@@ -1891,6 +2446,10 @@ define("ember-data/lib/main",
|
|
1891
2446
|
|
1892
2447
|
DS.ContainerProxy = ContainerProxy;
|
1893
2448
|
|
2449
|
+
DS._setupContainer = setupContainer;
|
2450
|
+
|
2451
|
+
Ember.lookup.DS = DS;
|
2452
|
+
|
1894
2453
|
__exports__["default"] = DS;
|
1895
2454
|
});
|
1896
2455
|
define("ember-data/lib/serializers",
|
@@ -1904,10 +2463,12 @@ define("ember-data/lib/serializers",
|
|
1904
2463
|
__exports__.RESTSerializer = RESTSerializer;
|
1905
2464
|
});
|
1906
2465
|
define("ember-data/lib/serializers/json_serializer",
|
1907
|
-
["exports"],
|
1908
|
-
function(__exports__) {
|
2466
|
+
["../system/changes","exports"],
|
2467
|
+
function(__dependency1__, __exports__) {
|
1909
2468
|
"use strict";
|
1910
|
-
var
|
2469
|
+
var RelationshipChange = __dependency1__.RelationshipChange;
|
2470
|
+
var get = Ember.get, set = Ember.set, isNone = Ember.isNone,
|
2471
|
+
map = Ember.ArrayPolyfills.map;
|
1911
2472
|
|
1912
2473
|
/**
|
1913
2474
|
In Ember Data a Serializer is used to serialize and deserialize
|
@@ -1947,6 +2508,35 @@ define("ember-data/lib/serializers/json_serializer",
|
|
1947
2508
|
*/
|
1948
2509
|
primaryKey: 'id',
|
1949
2510
|
|
2511
|
+
/**
|
2512
|
+
The `attrs` object can be used to declare a simple mapping between
|
2513
|
+
property names on `DS.Model` records and payload keys in the
|
2514
|
+
serialized JSON object representing the record. An object with the
|
2515
|
+
propery `key` can also be used to designate the attribute's key on
|
2516
|
+
the response payload.
|
2517
|
+
|
2518
|
+
Example
|
2519
|
+
|
2520
|
+
```javascript
|
2521
|
+
App.Person = DS.Model.extend({
|
2522
|
+
firstName: DS.attr('string'),
|
2523
|
+
lastName: DS.attr('string'),
|
2524
|
+
occupation: DS.attr('string'),
|
2525
|
+
admin: DS.attr('boolean')
|
2526
|
+
});
|
2527
|
+
|
2528
|
+
App.PersonSerializer = DS.JSONSerializer.extend({
|
2529
|
+
attrs: {
|
2530
|
+
admin: 'is_admin',
|
2531
|
+
occupation: {key: 'career'}
|
2532
|
+
}
|
2533
|
+
});
|
2534
|
+
```
|
2535
|
+
|
2536
|
+
@property attrs
|
2537
|
+
@type {Object}
|
2538
|
+
*/
|
2539
|
+
|
1950
2540
|
/**
|
1951
2541
|
Given a subclass of `DS.Model` and a JSON object this method will
|
1952
2542
|
iterate through each attribute of the `DS.Model` and invoke the
|
@@ -2007,10 +2597,45 @@ define("ember-data/lib/serializers/json_serializer",
|
|
2007
2597
|
normalize: function(type, hash) {
|
2008
2598
|
if (!hash) { return hash; }
|
2009
2599
|
|
2600
|
+
this.normalizeId(hash);
|
2601
|
+
this.normalizeUsingDeclaredMapping(type, hash);
|
2010
2602
|
this.applyTransforms(type, hash);
|
2011
2603
|
return hash;
|
2012
2604
|
},
|
2013
2605
|
|
2606
|
+
/**
|
2607
|
+
@method normalizeUsingDeclaredMapping
|
2608
|
+
@private
|
2609
|
+
*/
|
2610
|
+
normalizeUsingDeclaredMapping: function(type, hash) {
|
2611
|
+
var attrs = get(this, 'attrs'), payloadKey, key;
|
2612
|
+
|
2613
|
+
if (attrs) {
|
2614
|
+
for (key in attrs) {
|
2615
|
+
payloadKey = attrs[key];
|
2616
|
+
if (payloadKey && payloadKey.key) {
|
2617
|
+
payloadKey = payloadKey.key;
|
2618
|
+
}
|
2619
|
+
if (typeof payloadKey === 'string') {
|
2620
|
+
hash[key] = hash[payloadKey];
|
2621
|
+
delete hash[payloadKey];
|
2622
|
+
}
|
2623
|
+
}
|
2624
|
+
}
|
2625
|
+
},
|
2626
|
+
/**
|
2627
|
+
@method normalizeId
|
2628
|
+
@private
|
2629
|
+
*/
|
2630
|
+
normalizeId: function(hash) {
|
2631
|
+
var primaryKey = get(this, 'primaryKey');
|
2632
|
+
|
2633
|
+
if (primaryKey === 'id') { return; }
|
2634
|
+
|
2635
|
+
hash.id = hash[primaryKey];
|
2636
|
+
delete hash[primaryKey];
|
2637
|
+
},
|
2638
|
+
|
2014
2639
|
// SERIALIZE
|
2015
2640
|
/**
|
2016
2641
|
Called when a record is saved in order to convert the
|
@@ -2185,7 +2810,7 @@ define("ember-data/lib/serializers/json_serializer",
|
|
2185
2810
|
`serializeAttribute` can be used to customize how `DS.attr`
|
2186
2811
|
properties are serialized
|
2187
2812
|
|
2188
|
-
For example if you wanted to ensure all
|
2813
|
+
For example if you wanted to ensure all your attributes were always
|
2189
2814
|
serialized as properties on an `attributes` object you could
|
2190
2815
|
write:
|
2191
2816
|
|
@@ -2289,11 +2914,11 @@ define("ember-data/lib/serializers/json_serializer",
|
|
2289
2914
|
*/
|
2290
2915
|
serializeHasMany: function(record, json, relationship) {
|
2291
2916
|
var key = relationship.key;
|
2292
|
-
|
2293
|
-
var relationshipType =
|
2917
|
+
var payloadKey = this.keyForRelationship ? this.keyForRelationship(key, "hasMany") : key;
|
2918
|
+
var relationshipType = RelationshipChange.determineRelationshipType(record.constructor, relationship);
|
2294
2919
|
|
2295
2920
|
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany') {
|
2296
|
-
json[
|
2921
|
+
json[payloadKey] = get(record, key).mapBy('id');
|
2297
2922
|
// TODO support for polymorphic manyToNone and manyToMany relationships
|
2298
2923
|
}
|
2299
2924
|
},
|
@@ -2557,8 +3182,11 @@ define("ember-data/lib/serializers/json_serializer",
|
|
2557
3182
|
@param {Object} payload
|
2558
3183
|
@return {Array} array An array of deserialized objects
|
2559
3184
|
*/
|
2560
|
-
extractArray: function(store, type,
|
2561
|
-
|
3185
|
+
extractArray: function(store, type, arrayPayload) {
|
3186
|
+
var serializer = this;
|
3187
|
+
return map.call(arrayPayload, function(singlePayload) {
|
3188
|
+
return serializer.normalize(type, singlePayload);
|
3189
|
+
});
|
2562
3190
|
},
|
2563
3191
|
|
2564
3192
|
/**
|
@@ -2651,8 +3279,8 @@ define("ember-data/lib/serializers/json_serializer",
|
|
2651
3279
|
__exports__["default"] = JSONSerializer;
|
2652
3280
|
});
|
2653
3281
|
define("ember-data/lib/serializers/rest_serializer",
|
2654
|
-
["./json_serializer","exports"],
|
2655
|
-
function(__dependency1__, __exports__) {
|
3282
|
+
["./json_serializer","ember-inflector/lib/system/string","exports"],
|
3283
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
2656
3284
|
"use strict";
|
2657
3285
|
/**
|
2658
3286
|
@module ember-data
|
@@ -2663,6 +3291,9 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
2663
3291
|
var forEach = Ember.ArrayPolyfills.forEach;
|
2664
3292
|
var map = Ember.ArrayPolyfills.map;
|
2665
3293
|
|
3294
|
+
var singularize = __dependency2__.singularize;
|
3295
|
+
var camelize = Ember.String.camelize;
|
3296
|
+
|
2666
3297
|
function coerceId(id) {
|
2667
3298
|
return id == null ? null : id+'';
|
2668
3299
|
}
|
@@ -2819,7 +3450,7 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
2819
3450
|
@param {subclass of DS.Model} type
|
2820
3451
|
@param {Object} hash
|
2821
3452
|
@param {String} prop
|
2822
|
-
@
|
3453
|
+
@return {Object}
|
2823
3454
|
*/
|
2824
3455
|
normalize: function(type, hash, prop) {
|
2825
3456
|
this.normalizeId(hash);
|
@@ -2832,7 +3463,8 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
2832
3463
|
this.normalizeHash[prop](hash);
|
2833
3464
|
}
|
2834
3465
|
|
2835
|
-
|
3466
|
+
this.applyTransforms(type, hash);
|
3467
|
+
return hash;
|
2836
3468
|
},
|
2837
3469
|
|
2838
3470
|
/**
|
@@ -2843,7 +3475,7 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
2843
3475
|
|
2844
3476
|
```js
|
2845
3477
|
App.ApplicationSerializer = DS.RESTSerializer.extend({
|
2846
|
-
normalizePayload: function(
|
3478
|
+
normalizePayload: function(payload) {
|
2847
3479
|
delete payload.version;
|
2848
3480
|
delete payload.status;
|
2849
3481
|
return payload;
|
@@ -2852,48 +3484,13 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
2852
3484
|
```
|
2853
3485
|
|
2854
3486
|
@method normalizePayload
|
2855
|
-
@param {
|
2856
|
-
@
|
2857
|
-
@returns {Object} the normalized payload
|
3487
|
+
@param {Object} payload
|
3488
|
+
@return {Object} the normalized payload
|
2858
3489
|
*/
|
2859
|
-
normalizePayload: function(
|
3490
|
+
normalizePayload: function(payload) {
|
2860
3491
|
return payload;
|
2861
3492
|
},
|
2862
3493
|
|
2863
|
-
/**
|
2864
|
-
@method normalizeId
|
2865
|
-
@private
|
2866
|
-
*/
|
2867
|
-
normalizeId: function(hash) {
|
2868
|
-
var primaryKey = get(this, 'primaryKey');
|
2869
|
-
|
2870
|
-
if (primaryKey === 'id') { return; }
|
2871
|
-
|
2872
|
-
hash.id = hash[primaryKey];
|
2873
|
-
delete hash[primaryKey];
|
2874
|
-
},
|
2875
|
-
|
2876
|
-
/**
|
2877
|
-
@method normalizeUsingDeclaredMapping
|
2878
|
-
@private
|
2879
|
-
*/
|
2880
|
-
normalizeUsingDeclaredMapping: function(type, hash) {
|
2881
|
-
var attrs = get(this, 'attrs'), payloadKey, key;
|
2882
|
-
|
2883
|
-
if (attrs) {
|
2884
|
-
for (key in attrs) {
|
2885
|
-
payloadKey = attrs[key];
|
2886
|
-
if (payloadKey && payloadKey.key) {
|
2887
|
-
payloadKey = payloadKey.key;
|
2888
|
-
}
|
2889
|
-
if (typeof payloadKey === 'string') {
|
2890
|
-
hash[key] = hash[payloadKey];
|
2891
|
-
delete hash[payloadKey];
|
2892
|
-
}
|
2893
|
-
}
|
2894
|
-
}
|
2895
|
-
},
|
2896
|
-
|
2897
3494
|
/**
|
2898
3495
|
@method normalizeAttributes
|
2899
3496
|
@private
|
@@ -2966,12 +3563,12 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
2966
3563
|
```js
|
2967
3564
|
App.PostSerializer = DS.RESTSerializer.extend({
|
2968
3565
|
// First, restructure the top-level so it's organized by type
|
2969
|
-
extractSingle: function(store, type, payload, id
|
3566
|
+
extractSingle: function(store, type, payload, id) {
|
2970
3567
|
var comments = payload._embedded.comment;
|
2971
3568
|
delete payload._embedded;
|
2972
3569
|
|
2973
3570
|
payload = { comments: comments, post: payload };
|
2974
|
-
return this._super(store, type, payload, id
|
3571
|
+
return this._super(store, type, payload, id);
|
2975
3572
|
},
|
2976
3573
|
|
2977
3574
|
normalizeHash: {
|
@@ -3001,15 +3598,13 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3001
3598
|
|
3002
3599
|
@method extractSingle
|
3003
3600
|
@param {DS.Store} store
|
3004
|
-
@param {subclass of DS.Model}
|
3601
|
+
@param {subclass of DS.Model} primaryType
|
3005
3602
|
@param {Object} payload
|
3006
|
-
@param {String}
|
3007
|
-
@
|
3008
|
-
@returns {Object} the primary response to the original request
|
3603
|
+
@param {String} recordId
|
3604
|
+
@return {Object} the primary response to the original request
|
3009
3605
|
*/
|
3010
|
-
extractSingle: function(store, primaryType, payload, recordId
|
3011
|
-
payload = this.normalizePayload(
|
3012
|
-
|
3606
|
+
extractSingle: function(store, primaryType, payload, recordId) {
|
3607
|
+
payload = this.normalizePayload(payload);
|
3013
3608
|
var primaryTypeName = primaryType.typeKey,
|
3014
3609
|
primaryRecord;
|
3015
3610
|
|
@@ -3095,7 +3690,7 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3095
3690
|
App.PostSerializer = DS.RESTSerializer.extend({
|
3096
3691
|
// First, restructure the top-level so it's organized by type
|
3097
3692
|
// and the comments are listed under a post's `comments` key.
|
3098
|
-
extractArray: function(store, type, payload
|
3693
|
+
extractArray: function(store, type, payload) {
|
3099
3694
|
var posts = payload._embedded.post;
|
3100
3695
|
var comments = [];
|
3101
3696
|
var postCache = {};
|
@@ -3113,7 +3708,7 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3113
3708
|
|
3114
3709
|
payload = { comments: comments, posts: payload };
|
3115
3710
|
|
3116
|
-
return this._super(store, type, payload
|
3711
|
+
return this._super(store, type, payload);
|
3117
3712
|
},
|
3118
3713
|
|
3119
3714
|
normalizeHash: {
|
@@ -3147,14 +3742,13 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3147
3742
|
|
3148
3743
|
@method extractArray
|
3149
3744
|
@param {DS.Store} store
|
3150
|
-
@param {subclass of DS.Model}
|
3745
|
+
@param {subclass of DS.Model} primaryType
|
3151
3746
|
@param {Object} payload
|
3152
|
-
@
|
3153
|
-
@returns {Array} The primary array that was returned in response
|
3747
|
+
@return {Array} The primary array that was returned in response
|
3154
3748
|
to the original query.
|
3155
3749
|
*/
|
3156
3750
|
extractArray: function(store, primaryType, payload) {
|
3157
|
-
payload = this.normalizePayload(
|
3751
|
+
payload = this.normalizePayload(payload);
|
3158
3752
|
|
3159
3753
|
var primaryTypeName = primaryType.typeKey,
|
3160
3754
|
primaryArray;
|
@@ -3220,15 +3814,16 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3220
3814
|
@param {Object} payload
|
3221
3815
|
*/
|
3222
3816
|
pushPayload: function(store, payload) {
|
3223
|
-
payload = this.normalizePayload(
|
3817
|
+
payload = this.normalizePayload(payload);
|
3224
3818
|
|
3225
3819
|
for (var prop in payload) {
|
3226
3820
|
var typeName = this.typeForRoot(prop),
|
3227
|
-
type = store.modelFor(typeName)
|
3821
|
+
type = store.modelFor(typeName),
|
3822
|
+
typeSerializer = store.serializerFor(type);
|
3228
3823
|
|
3229
3824
|
/*jshint loopfunc:true*/
|
3230
3825
|
var normalizedArray = map.call(Ember.makeArray(payload[prop]), function(hash) {
|
3231
|
-
return
|
3826
|
+
return typeSerializer.normalize(type, hash, prop);
|
3232
3827
|
}, this);
|
3233
3828
|
|
3234
3829
|
store.pushMany(typeName, normalizedArray);
|
@@ -3236,27 +3831,50 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3236
3831
|
},
|
3237
3832
|
|
3238
3833
|
/**
|
3239
|
-
|
3240
|
-
into
|
3834
|
+
This method is used to convert each JSON root key in the payload
|
3835
|
+
into a typeKey that it can use to look up the appropriate model for
|
3836
|
+
that part of the payload. By default the typeKey for a model is its
|
3837
|
+
name in camelCase, so if your JSON root key is 'fast-car' you would
|
3838
|
+
use typeForRoot to convert it to 'fastCar' so that Ember Data finds
|
3839
|
+
the `FastCar` model.
|
3840
|
+
|
3841
|
+
If you diverge from this norm you should also consider changes to
|
3842
|
+
store._normalizeTypeKey as well.
|
3843
|
+
|
3844
|
+
For example, your server may return prefixed root keys like so:
|
3845
|
+
|
3846
|
+
```js
|
3847
|
+
{
|
3848
|
+
"response-fast-car": {
|
3849
|
+
"id": "1",
|
3850
|
+
"name": "corvette"
|
3851
|
+
}
|
3852
|
+
}
|
3853
|
+
```
|
3241
3854
|
|
3242
|
-
|
3243
|
-
the
|
3855
|
+
In order for Ember Data to know that the model corresponding to
|
3856
|
+
the 'response-fast-car' hash is `FastCar` (typeKey: 'fastCar'),
|
3857
|
+
you can override typeForRoot to convert 'response-fast-car' to
|
3858
|
+
'fastCar' like so:
|
3244
3859
|
|
3245
3860
|
```js
|
3246
3861
|
App.ApplicationSerializer = DS.RESTSerializer.extend({
|
3247
3862
|
typeForRoot: function(root) {
|
3248
|
-
|
3249
|
-
|
3863
|
+
// 'response-fast-car' should become 'fast-car'
|
3864
|
+
var subRoot = root.substring(9);
|
3865
|
+
|
3866
|
+
// _super normalizes 'fast-car' to 'fastCar'
|
3867
|
+
return this._super(subRoot);
|
3250
3868
|
}
|
3251
3869
|
});
|
3252
3870
|
```
|
3253
3871
|
|
3254
3872
|
@method typeForRoot
|
3255
|
-
@param {String}
|
3256
|
-
@
|
3873
|
+
@param {String} key
|
3874
|
+
@return {String} the model's typeKey
|
3257
3875
|
*/
|
3258
|
-
typeForRoot: function(
|
3259
|
-
return
|
3876
|
+
typeForRoot: function(key) {
|
3877
|
+
return camelize(singularize(key));
|
3260
3878
|
},
|
3261
3879
|
|
3262
3880
|
// SERIALIZE
|
@@ -3409,7 +4027,9 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3409
4027
|
|
3410
4028
|
/**
|
3411
4029
|
You can use this method to customize the root keys serialized into the JSON.
|
3412
|
-
By default the REST Serializer sends
|
4030
|
+
By default the REST Serializer sends the typeKey of a model, whih is a camelized
|
4031
|
+
version of the name.
|
4032
|
+
|
3413
4033
|
For example, your server may expect underscored root objects.
|
3414
4034
|
|
3415
4035
|
```js
|
@@ -3428,8 +4048,7 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3428
4048
|
@param {Object} options
|
3429
4049
|
*/
|
3430
4050
|
serializeIntoHash: function(hash, type, record, options) {
|
3431
|
-
|
3432
|
-
hash[root] = this.serialize(record, options);
|
4051
|
+
hash[type.typeKey] = this.serialize(record, options);
|
3433
4052
|
},
|
3434
4053
|
|
3435
4054
|
/**
|
@@ -3446,12 +4065,34 @@ define("ember-data/lib/serializers/rest_serializer",
|
|
3446
4065
|
var key = relationship.key,
|
3447
4066
|
belongsTo = get(record, key);
|
3448
4067
|
key = this.keyForAttribute ? this.keyForAttribute(key) : key;
|
3449
|
-
json[key + "Type"] =
|
4068
|
+
json[key + "Type"] = belongsTo.constructor.typeKey;
|
3450
4069
|
}
|
3451
4070
|
});
|
3452
4071
|
|
3453
4072
|
__exports__["default"] = RESTSerializer;
|
3454
4073
|
});
|
4074
|
+
define("ember-data/lib/setup-container",
|
4075
|
+
["./initializers/store","./initializers/transforms","./initializers/store_injections","./initializers/data_adapter","../../../activemodel-adapter/lib/setup-container","exports"],
|
4076
|
+
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __exports__) {
|
4077
|
+
"use strict";
|
4078
|
+
var initializeStore = __dependency1__["default"];
|
4079
|
+
var initializeTransforms = __dependency2__["default"];
|
4080
|
+
var initializeStoreInjections = __dependency3__["default"];
|
4081
|
+
var initializeDataAdapter = __dependency4__["default"];
|
4082
|
+
var setupActiveModelContainer = __dependency5__["default"];
|
4083
|
+
|
4084
|
+
__exports__["default"] = function setupContainer(container, application){
|
4085
|
+
// application is not a required argument. This ensures
|
4086
|
+
// testing setups can setup a container without booting an
|
4087
|
+
// entire ember application.
|
4088
|
+
|
4089
|
+
initializeDataAdapter(container, application);
|
4090
|
+
initializeTransforms(container, application);
|
4091
|
+
initializeStoreInjections(container, application);
|
4092
|
+
initializeStore(container, application);
|
4093
|
+
setupActiveModelContainer(container, application);
|
4094
|
+
};
|
4095
|
+
});
|
3455
4096
|
define("ember-data/lib/system/adapter",
|
3456
4097
|
["exports"],
|
3457
4098
|
function(__exports__) {
|
@@ -3490,11 +4131,11 @@ define("ember-data/lib/system/adapter",
|
|
3490
4131
|
}
|
3491
4132
|
});
|
3492
4133
|
```
|
3493
|
-
|
4134
|
+
|
3494
4135
|
The `DS.InvalidError` must be constructed with a single object whose
|
3495
4136
|
keys are the invalid model properties, and whose values are the
|
3496
4137
|
corresponding error messages. For example:
|
3497
|
-
|
4138
|
+
|
3498
4139
|
```javascript
|
3499
4140
|
return new DS.InvalidError({
|
3500
4141
|
length: 'Must be less than 15',
|
@@ -3525,20 +4166,26 @@ define("ember-data/lib/system/adapter",
|
|
3525
4166
|
|
3526
4167
|
### Creating an Adapter
|
3527
4168
|
|
3528
|
-
|
4169
|
+
Create a new subclass of `DS.Adapter`, then assign
|
4170
|
+
it to the `ApplicationAdapter` property of the application.
|
3529
4171
|
|
3530
4172
|
```javascript
|
3531
|
-
|
4173
|
+
var MyAdapter = DS.Adapter.extend({
|
3532
4174
|
// ...your code here
|
3533
4175
|
});
|
4176
|
+
|
4177
|
+
App.ApplicationAdapter = MyAdapter;
|
3534
4178
|
```
|
3535
4179
|
|
3536
|
-
|
4180
|
+
Model-specific adapters can be created by assigning your adapter
|
4181
|
+
class to the `ModelName` + `Adapter` property of the application.
|
3537
4182
|
|
3538
4183
|
```javascript
|
3539
|
-
|
3540
|
-
adapter
|
4184
|
+
var MyPostAdapter = DS.Adapter.extend({
|
4185
|
+
// ...Post-specific adapter code goes here
|
3541
4186
|
});
|
4187
|
+
|
4188
|
+
App.PostAdapter = MyPostAdapter;
|
3542
4189
|
```
|
3543
4190
|
|
3544
4191
|
`DS.Adapter` is an abstract base class that you should override in your
|
@@ -3903,24 +4550,21 @@ define("ember-data/lib/system/adapter",
|
|
3903
4550
|
__exports__["default"] = Adapter;
|
3904
4551
|
});
|
3905
4552
|
define("ember-data/lib/system/changes",
|
3906
|
-
["./changes/
|
3907
|
-
function(__dependency1__,
|
4553
|
+
["./changes/relationship_change","exports"],
|
4554
|
+
function(__dependency1__, __exports__) {
|
3908
4555
|
"use strict";
|
3909
4556
|
/**
|
3910
4557
|
@module ember-data
|
3911
4558
|
*/
|
3912
4559
|
|
3913
|
-
var
|
4560
|
+
var RelationshipChange = __dependency1__.RelationshipChange;
|
4561
|
+
var RelationshipChangeAdd = __dependency1__.RelationshipChangeAdd;
|
4562
|
+
var RelationshipChangeRemove = __dependency1__.RelationshipChangeRemove;
|
4563
|
+
var OneToManyChange = __dependency1__.OneToManyChange;
|
4564
|
+
var ManyToNoneChange = __dependency1__.ManyToNoneChange;
|
4565
|
+
var OneToOneChange = __dependency1__.OneToOneChange;
|
4566
|
+
var ManyToManyChange = __dependency1__.ManyToManyChange;
|
3914
4567
|
|
3915
|
-
var RelationshipChange = __dependency2__.RelationshipChange;
|
3916
|
-
var RelationshipChangeAdd = __dependency2__.RelationshipChangeAdd;
|
3917
|
-
var RelationshipChangeRemove = __dependency2__.RelationshipChangeRemove;
|
3918
|
-
var OneToManyChange = __dependency2__.OneToManyChange;
|
3919
|
-
var ManyToNoneChange = __dependency2__.ManyToNoneChange;
|
3920
|
-
var OneToOneChange = __dependency2__.OneToOneChange;
|
3921
|
-
var ManyToManyChange = __dependency2__.ManyToManyChange;
|
3922
|
-
|
3923
|
-
__exports__.AttributeChange = AttributeChange;
|
3924
4568
|
__exports__.RelationshipChange = RelationshipChange;
|
3925
4569
|
__exports__.RelationshipChangeAdd = RelationshipChangeAdd;
|
3926
4570
|
__exports__.RelationshipChangeRemove = RelationshipChangeRemove;
|
@@ -3929,61 +4573,6 @@ define("ember-data/lib/system/changes",
|
|
3929
4573
|
__exports__.OneToOneChange = OneToOneChange;
|
3930
4574
|
__exports__.ManyToManyChange = ManyToManyChange;
|
3931
4575
|
});
|
3932
|
-
define("ember-data/lib/system/changes/attribute_change",
|
3933
|
-
["exports"],
|
3934
|
-
function(__exports__) {
|
3935
|
-
"use strict";
|
3936
|
-
/**
|
3937
|
-
@module ember-data
|
3938
|
-
*/
|
3939
|
-
|
3940
|
-
/**
|
3941
|
-
An AttributeChange object is created whenever a record's
|
3942
|
-
attribute changes value. It is used to track changes to a
|
3943
|
-
record between transaction commits.
|
3944
|
-
|
3945
|
-
@class AttributeChange
|
3946
|
-
@namespace DS
|
3947
|
-
@private
|
3948
|
-
@constructor
|
3949
|
-
*/
|
3950
|
-
function AttributeChange(options) {
|
3951
|
-
this.record = options.record;
|
3952
|
-
this.store = options.store;
|
3953
|
-
this.name = options.name;
|
3954
|
-
this.value = options.value;
|
3955
|
-
this.oldValue = options.oldValue;
|
3956
|
-
}
|
3957
|
-
|
3958
|
-
AttributeChange.createChange = function(options) {
|
3959
|
-
return new AttributeChange(options);
|
3960
|
-
};
|
3961
|
-
|
3962
|
-
AttributeChange.prototype = {
|
3963
|
-
sync: function() {
|
3964
|
-
if (this.value !== this.oldValue) {
|
3965
|
-
this.record.send('becomeDirty');
|
3966
|
-
this.record.updateRecordArraysLater();
|
3967
|
-
}
|
3968
|
-
|
3969
|
-
// TODO: Use this object in the commit process
|
3970
|
-
this.destroy();
|
3971
|
-
},
|
3972
|
-
|
3973
|
-
/**
|
3974
|
-
If the AttributeChange is destroyed (either by being rolled back
|
3975
|
-
or being committed), remove it from the list of pending changes
|
3976
|
-
on the record.
|
3977
|
-
|
3978
|
-
@method destroy
|
3979
|
-
*/
|
3980
|
-
destroy: function() {
|
3981
|
-
delete this.record._changesToSync[this.name];
|
3982
|
-
}
|
3983
|
-
};
|
3984
|
-
|
3985
|
-
__exports__["default"] = AttributeChange;
|
3986
|
-
});
|
3987
4576
|
define("ember-data/lib/system/changes/relationship_change",
|
3988
4577
|
["../model","exports"],
|
3989
4578
|
function(__dependency1__, __exports__) {
|
@@ -4959,6 +5548,8 @@ define("ember-data/lib/system/model/attributes",
|
|
4959
5548
|
`boolean` and `date`. You can define your own transforms by subclassing
|
4960
5549
|
[DS.Transform](/api/data/classes/DS.Transform.html).
|
4961
5550
|
|
5551
|
+
Note that you cannot use `attr` to define an attribute of `id`.
|
5552
|
+
|
4962
5553
|
`DS.attr` takes an optional hash as a second parameter, currently
|
4963
5554
|
supported options are:
|
4964
5555
|
|
@@ -5032,6 +5623,7 @@ define("ember-data/lib/system/model/errors",
|
|
5032
5623
|
function(__exports__) {
|
5033
5624
|
"use strict";
|
5034
5625
|
var get = Ember.get, isEmpty = Ember.isEmpty;
|
5626
|
+
var map = Ember.EnumerableUtils.map;
|
5035
5627
|
|
5036
5628
|
/**
|
5037
5629
|
@module ember-data
|
@@ -5040,6 +5632,65 @@ define("ember-data/lib/system/model/errors",
|
|
5040
5632
|
/**
|
5041
5633
|
Holds validation errors for a given record organized by attribute names.
|
5042
5634
|
|
5635
|
+
Every DS.Model has an `errors` property that is an instance of
|
5636
|
+
`DS.Errors`. This can be used to display validation error
|
5637
|
+
messages returned from the server when a `record.save()` rejects.
|
5638
|
+
|
5639
|
+
For Example, if you had an `User` model that looked like this:
|
5640
|
+
|
5641
|
+
```javascript
|
5642
|
+
App.User = DS.Model.extend({
|
5643
|
+
username: attr('string'),
|
5644
|
+
email: attr('string')
|
5645
|
+
});
|
5646
|
+
```
|
5647
|
+
And you attempted to save a record that did not validate on the backend.
|
5648
|
+
|
5649
|
+
```javascript
|
5650
|
+
var user = store.createRecord('user', {
|
5651
|
+
username: 'tomster',
|
5652
|
+
email: 'invalidEmail'
|
5653
|
+
});
|
5654
|
+
user.save();
|
5655
|
+
```
|
5656
|
+
|
5657
|
+
Your backend data store might return a response that looks like
|
5658
|
+
this. This response will be used to populate the error object.
|
5659
|
+
|
5660
|
+
```javascript
|
5661
|
+
{
|
5662
|
+
"errors": {
|
5663
|
+
"username": ["This username is already taken!"],
|
5664
|
+
"email": ["Doesn't look like a valid email."]
|
5665
|
+
}
|
5666
|
+
}
|
5667
|
+
```
|
5668
|
+
|
5669
|
+
Errors can be displayed to the user by accessing their property name
|
5670
|
+
or using the `messages` property to get an array of all errors.
|
5671
|
+
|
5672
|
+
```handlebars
|
5673
|
+
{{#each errors.messages}}
|
5674
|
+
<div class="error">
|
5675
|
+
{{message}}
|
5676
|
+
</div>
|
5677
|
+
{{/each}}
|
5678
|
+
|
5679
|
+
<label>Username: {{input value=username}} </label>
|
5680
|
+
{{#each errors.username}}
|
5681
|
+
<div class="error">
|
5682
|
+
{{message}}
|
5683
|
+
</div>
|
5684
|
+
{{/each}}
|
5685
|
+
|
5686
|
+
<label>Email: {{input value=email}} </label>
|
5687
|
+
{{#each errors.email}}
|
5688
|
+
<div class="error">
|
5689
|
+
{{message}}
|
5690
|
+
</div>
|
5691
|
+
{{/each}}
|
5692
|
+
```
|
5693
|
+
|
5043
5694
|
@class Errors
|
5044
5695
|
@namespace DS
|
5045
5696
|
@extends Ember.Object
|
@@ -5090,15 +5741,38 @@ define("ember-data/lib/system/model/errors",
|
|
5090
5741
|
/**
|
5091
5742
|
Returns errors for a given attribute
|
5092
5743
|
|
5744
|
+
```javascript
|
5745
|
+
var user = store.createRecord('user', {
|
5746
|
+
username: 'tomster',
|
5747
|
+
email: 'invalidEmail'
|
5748
|
+
});
|
5749
|
+
user.save().catch(function(){
|
5750
|
+
user.get('errors').errorsFor('email'); // ["Doesn't look like a valid email."]
|
5751
|
+
});
|
5752
|
+
```
|
5753
|
+
|
5093
5754
|
@method errorsFor
|
5094
5755
|
@param {String} attribute
|
5095
|
-
@
|
5756
|
+
@return {Array}
|
5096
5757
|
*/
|
5097
5758
|
errorsFor: function(attribute) {
|
5098
5759
|
return get(this, 'errorsByAttributeName').get(attribute);
|
5099
5760
|
},
|
5100
5761
|
|
5101
5762
|
/**
|
5763
|
+
An array containing all of the error messages for this
|
5764
|
+
record. This is useful for displaying all errors to the user.
|
5765
|
+
|
5766
|
+
```handlebars
|
5767
|
+
{{#each errors.messages}}
|
5768
|
+
<div class="error">
|
5769
|
+
{{message}}
|
5770
|
+
</div>
|
5771
|
+
{{/each}}
|
5772
|
+
```
|
5773
|
+
|
5774
|
+
@property messages
|
5775
|
+
@type {Array}
|
5102
5776
|
*/
|
5103
5777
|
messages: Ember.computed.mapBy('content', 'message'),
|
5104
5778
|
|
@@ -5149,6 +5823,14 @@ define("ember-data/lib/system/model/errors",
|
|
5149
5823
|
Adds error messages to a given attribute and sends
|
5150
5824
|
`becameInvalid` event to the record.
|
5151
5825
|
|
5826
|
+
Example:
|
5827
|
+
|
5828
|
+
```javascript
|
5829
|
+
if (!user.get('username') {
|
5830
|
+
user.get('errors').add('username', 'This field is required');
|
5831
|
+
}
|
5832
|
+
```
|
5833
|
+
|
5152
5834
|
@method add
|
5153
5835
|
@param {String} attribute
|
5154
5836
|
@param {Array|String} messages
|
@@ -5174,7 +5856,7 @@ define("ember-data/lib/system/model/errors",
|
|
5174
5856
|
_findOrCreateMessages: function(attribute, messages) {
|
5175
5857
|
var errors = this.errorsFor(attribute);
|
5176
5858
|
|
5177
|
-
return Ember.makeArray(messages)
|
5859
|
+
return map(Ember.makeArray(messages), function(message) {
|
5178
5860
|
return errors.findBy('message', message) || {
|
5179
5861
|
attribute: attribute,
|
5180
5862
|
message: message
|
@@ -5186,6 +5868,27 @@ define("ember-data/lib/system/model/errors",
|
|
5186
5868
|
Removes all error messages from the given attribute and sends
|
5187
5869
|
`becameValid` event to the record if there no more errors left.
|
5188
5870
|
|
5871
|
+
Example:
|
5872
|
+
|
5873
|
+
```javascript
|
5874
|
+
App.User = DS.Model.extend({
|
5875
|
+
email: DS.attr('string'),
|
5876
|
+
twoFactorAuth: DS.attr('boolean'),
|
5877
|
+
phone: DS.attr('string')
|
5878
|
+
});
|
5879
|
+
|
5880
|
+
App.UserEditRoute = Ember.Route.extend({
|
5881
|
+
actions: {
|
5882
|
+
save: function(user) {
|
5883
|
+
if (!user.get('twoFactorAuth')) {
|
5884
|
+
user.get('errors').remove('phone');
|
5885
|
+
}
|
5886
|
+
user.save();
|
5887
|
+
}
|
5888
|
+
}
|
5889
|
+
});
|
5890
|
+
```
|
5891
|
+
|
5189
5892
|
@method remove
|
5190
5893
|
@param {String} attribute
|
5191
5894
|
*/
|
@@ -5207,6 +5910,19 @@ define("ember-data/lib/system/model/errors",
|
|
5207
5910
|
Removes all error messages and sends `becameValid` event
|
5208
5911
|
to the record.
|
5209
5912
|
|
5913
|
+
Example:
|
5914
|
+
|
5915
|
+
```javascript
|
5916
|
+
App.UserEditRoute = Ember.Route.extend({
|
5917
|
+
actions: {
|
5918
|
+
retrySave: function(user) {
|
5919
|
+
user.get('errors').clear();
|
5920
|
+
user.save();
|
5921
|
+
}
|
5922
|
+
}
|
5923
|
+
});
|
5924
|
+
```
|
5925
|
+
|
5210
5926
|
@method clear
|
5211
5927
|
*/
|
5212
5928
|
clear: function() {
|
@@ -5221,9 +5937,22 @@ define("ember-data/lib/system/model/errors",
|
|
5221
5937
|
/**
|
5222
5938
|
Checks if there is error messages for the given attribute.
|
5223
5939
|
|
5940
|
+
```javascript
|
5941
|
+
App.UserEditRoute = Ember.Route.extend({
|
5942
|
+
actions: {
|
5943
|
+
save: function(user) {
|
5944
|
+
if (user.get('errors').has('email')) {
|
5945
|
+
return alert('Please update your email before attempting to save.');
|
5946
|
+
}
|
5947
|
+
user.save();
|
5948
|
+
}
|
5949
|
+
}
|
5950
|
+
});
|
5951
|
+
```
|
5952
|
+
|
5224
5953
|
@method has
|
5225
5954
|
@param {String} attribute
|
5226
|
-
@
|
5955
|
+
@return {Boolean} true if there some errors on given attribute
|
5227
5956
|
*/
|
5228
5957
|
has: function(attribute) {
|
5229
5958
|
return !isEmpty(this.errorsFor(attribute));
|
@@ -5233,11 +5962,12 @@ define("ember-data/lib/system/model/errors",
|
|
5233
5962
|
__exports__["default"] = Errors;
|
5234
5963
|
});
|
5235
5964
|
define("ember-data/lib/system/model/model",
|
5236
|
-
["./states","./errors","exports"],
|
5237
|
-
function(__dependency1__, __dependency2__, __exports__) {
|
5965
|
+
["./states","./errors","../store","exports"],
|
5966
|
+
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
|
5238
5967
|
"use strict";
|
5239
5968
|
var RootState = __dependency1__["default"];
|
5240
5969
|
var Errors = __dependency2__["default"];
|
5970
|
+
var PromiseObject = __dependency3__.PromiseObject;
|
5241
5971
|
/**
|
5242
5972
|
@module ember-data
|
5243
5973
|
*/
|
@@ -5246,6 +5976,7 @@ define("ember-data/lib/system/model/model",
|
|
5246
5976
|
merge = Ember.merge,
|
5247
5977
|
Promise = Ember.RSVP.Promise;
|
5248
5978
|
|
5979
|
+
var JSONSerializer;
|
5249
5980
|
var retrieveFromCurrentState = Ember.computed('currentState', function(key, value) {
|
5250
5981
|
return get(get(this, 'currentState'), key);
|
5251
5982
|
}).readOnly();
|
@@ -5297,7 +6028,7 @@ define("ember-data/lib/system/model/model",
|
|
5297
6028
|
Example
|
5298
6029
|
|
5299
6030
|
```javascript
|
5300
|
-
var record = store.createRecord(
|
6031
|
+
var record = store.createRecord('model');
|
5301
6032
|
record.get('isLoaded'); // true
|
5302
6033
|
|
5303
6034
|
store.find('model', 1).then(function(model) {
|
@@ -5319,13 +6050,13 @@ define("ember-data/lib/system/model/model",
|
|
5319
6050
|
Example
|
5320
6051
|
|
5321
6052
|
```javascript
|
5322
|
-
var record = store.createRecord(
|
6053
|
+
var record = store.createRecord('model');
|
5323
6054
|
record.get('isDirty'); // true
|
5324
6055
|
|
5325
6056
|
store.find('model', 1).then(function(model) {
|
5326
6057
|
model.get('isDirty'); // false
|
5327
6058
|
model.set('foo', 'some value');
|
5328
|
-
model.
|
6059
|
+
model.get('isDirty'); // true
|
5329
6060
|
});
|
5330
6061
|
```
|
5331
6062
|
|
@@ -5343,7 +6074,7 @@ define("ember-data/lib/system/model/model",
|
|
5343
6074
|
Example
|
5344
6075
|
|
5345
6076
|
```javascript
|
5346
|
-
var record = store.createRecord(
|
6077
|
+
var record = store.createRecord('model');
|
5347
6078
|
record.get('isSaving'); // false
|
5348
6079
|
var promise = record.save();
|
5349
6080
|
record.get('isSaving'); // true
|
@@ -5368,10 +6099,26 @@ define("ember-data/lib/system/model/model",
|
|
5368
6099
|
Example
|
5369
6100
|
|
5370
6101
|
```javascript
|
5371
|
-
var record = store.createRecord(
|
5372
|
-
record.get('isDeleted');
|
6102
|
+
var record = store.createRecord('model');
|
6103
|
+
record.get('isDeleted'); // false
|
5373
6104
|
record.deleteRecord();
|
5374
|
-
|
6105
|
+
|
6106
|
+
// Locally deleted
|
6107
|
+
record.get('isDeleted'); // true
|
6108
|
+
record.get('isDirty'); // true
|
6109
|
+
record.get('isSaving'); // false
|
6110
|
+
|
6111
|
+
// Persisting the deletion
|
6112
|
+
var promise = record.save();
|
6113
|
+
record.get('isDeleted'); // true
|
6114
|
+
record.get('isSaving'); // true
|
6115
|
+
|
6116
|
+
// Deletion Persisted
|
6117
|
+
promise.then(function() {
|
6118
|
+
record.get('isDeleted'); // true
|
6119
|
+
record.get('isSaving'); // false
|
6120
|
+
record.get('isDirty'); // false
|
6121
|
+
});
|
5375
6122
|
```
|
5376
6123
|
|
5377
6124
|
@property isDeleted
|
@@ -5388,7 +6135,7 @@ define("ember-data/lib/system/model/model",
|
|
5388
6135
|
Example
|
5389
6136
|
|
5390
6137
|
```javascript
|
5391
|
-
var record = store.createRecord(
|
6138
|
+
var record = store.createRecord('model');
|
5392
6139
|
record.get('isNew'); // true
|
5393
6140
|
|
5394
6141
|
record.save().then(function(model) {
|
@@ -5402,9 +6149,9 @@ define("ember-data/lib/system/model/model",
|
|
5402
6149
|
*/
|
5403
6150
|
isNew: retrieveFromCurrentState,
|
5404
6151
|
/**
|
5405
|
-
If this property is `true` the record is in the `valid` state.
|
5406
|
-
|
5407
|
-
|
6152
|
+
If this property is `true` the record is in the `valid` state.
|
6153
|
+
|
6154
|
+
A record will be in the `valid` state when the adapter did not report any
|
5408
6155
|
server-side validation failures.
|
5409
6156
|
|
5410
6157
|
@property isValid
|
@@ -5424,7 +6171,7 @@ define("ember-data/lib/system/model/model",
|
|
5424
6171
|
Example
|
5425
6172
|
|
5426
6173
|
```javascript
|
5427
|
-
var record = store.createRecord(
|
6174
|
+
var record = store.createRecord('model');
|
5428
6175
|
record.get('dirtyType'); // 'created'
|
5429
6176
|
```
|
5430
6177
|
|
@@ -5436,15 +6183,14 @@ define("ember-data/lib/system/model/model",
|
|
5436
6183
|
|
5437
6184
|
/**
|
5438
6185
|
If `true` the adapter reported that it was unable to save local
|
5439
|
-
changes to the backend
|
5440
|
-
|
5441
|
-
server-side validations failed.
|
6186
|
+
changes to the backend for any reason other than a server-side
|
6187
|
+
validation error.
|
5442
6188
|
|
5443
6189
|
Example
|
5444
6190
|
|
5445
6191
|
```javascript
|
5446
6192
|
record.get('isError'); // false
|
5447
|
-
record.set('foo', '
|
6193
|
+
record.set('foo', 'valid value');
|
5448
6194
|
record.save().then(null, function() {
|
5449
6195
|
record.get('isError'); // true
|
5450
6196
|
});
|
@@ -5491,7 +6237,7 @@ define("ember-data/lib/system/model/model",
|
|
5491
6237
|
attribute.
|
5492
6238
|
|
5493
6239
|
```javascript
|
5494
|
-
var record = store.createRecord(
|
6240
|
+
var record = store.createRecord('model');
|
5495
6241
|
record.get('id'); // null
|
5496
6242
|
|
5497
6243
|
store.find('model', 1).then(function(model) {
|
@@ -5526,7 +6272,7 @@ define("ember-data/lib/system/model/model",
|
|
5526
6272
|
```
|
5527
6273
|
|
5528
6274
|
@property errors
|
5529
|
-
@type {
|
6275
|
+
@type {DS.Errors}
|
5530
6276
|
*/
|
5531
6277
|
errors: Ember.computed(function() {
|
5532
6278
|
var errors = Errors.create();
|
@@ -5552,7 +6298,7 @@ define("ember-data/lib/system/model/model",
|
|
5552
6298
|
|
5553
6299
|
@method serialize
|
5554
6300
|
@param {Object} options
|
5555
|
-
@
|
6301
|
+
@return {Object} an object whose values are primitive JSON values only
|
5556
6302
|
*/
|
5557
6303
|
serialize: function(options) {
|
5558
6304
|
var store = get(this, 'store');
|
@@ -5571,11 +6317,12 @@ define("ember-data/lib/system/model/model",
|
|
5571
6317
|
|
5572
6318
|
@method toJSON
|
5573
6319
|
@param {Object} options
|
5574
|
-
@
|
6320
|
+
@return {Object} A JSON representation of the object.
|
5575
6321
|
*/
|
5576
6322
|
toJSON: function(options) {
|
6323
|
+
if (!JSONSerializer) { JSONSerializer = requireModule("ember-data/lib/serializers/json_serializer")["default"]; }
|
5577
6324
|
// container is for lazy transform lookups
|
5578
|
-
var serializer =
|
6325
|
+
var serializer = JSONSerializer.create({ container: this.container });
|
5579
6326
|
return serializer.serialize(this, options);
|
5580
6327
|
},
|
5581
6328
|
|
@@ -6126,7 +6873,7 @@ define("ember-data/lib/system/model/model",
|
|
6126
6873
|
this._inFlightAttributes = this._attributes;
|
6127
6874
|
this._attributes = {};
|
6128
6875
|
|
6129
|
-
return
|
6876
|
+
return PromiseObject.create({ promise: resolver.promise });
|
6130
6877
|
},
|
6131
6878
|
|
6132
6879
|
/**
|
@@ -6170,7 +6917,7 @@ define("ember-data/lib/system/model/model",
|
|
6170
6917
|
throw reason;
|
6171
6918
|
}, "DS: Model#reload complete, update flags");
|
6172
6919
|
|
6173
|
-
return
|
6920
|
+
return PromiseObject.create({ promise: promise });
|
6174
6921
|
},
|
6175
6922
|
|
6176
6923
|
// FOR USE DURING COMMIT PROCESS
|
@@ -6505,8 +7252,8 @@ define("ember-data/lib/system/model/states",
|
|
6505
7252
|
// adapter reported that server-side validations failed.
|
6506
7253
|
// * isNew: The record was created on the client and the adapter
|
6507
7254
|
// did not yet report that it was successfully saved.
|
6508
|
-
// * isValid:
|
6509
|
-
//
|
7255
|
+
// * isValid: The adapter did not report any server-side validation
|
7256
|
+
// failures.
|
6510
7257
|
|
6511
7258
|
// The dirty state is a abstract state whose functionality is
|
6512
7259
|
// shared between the `created` and `updated` states.
|
@@ -6611,8 +7358,7 @@ define("ember-data/lib/system/model/states",
|
|
6611
7358
|
}
|
6612
7359
|
},
|
6613
7360
|
|
6614
|
-
// A record is in the `invalid`
|
6615
|
-
// invalidations have failed, or if the adapter has indicated
|
7361
|
+
// A record is in the `invalid` if the adapter has indicated
|
6616
7362
|
// the the record failed server-side invalidations.
|
6617
7363
|
invalid: {
|
6618
7364
|
// FLAGS
|
@@ -6632,6 +7378,11 @@ define("ember-data/lib/system/model/states",
|
|
6632
7378
|
|
6633
7379
|
becomeDirty: Ember.K,
|
6634
7380
|
|
7381
|
+
willCommit: function(record) {
|
7382
|
+
get(record, 'errors').clear();
|
7383
|
+
record.transitionTo('inFlight');
|
7384
|
+
},
|
7385
|
+
|
6635
7386
|
rolledBack: function(record) {
|
6636
7387
|
get(record, 'errors').clear();
|
6637
7388
|
},
|
@@ -6642,6 +7393,10 @@ define("ember-data/lib/system/model/states",
|
|
6642
7393
|
|
6643
7394
|
invokeLifecycleCallbacks: function(record) {
|
6644
7395
|
record.triggerLater('becameInvalid', record);
|
7396
|
+
},
|
7397
|
+
|
7398
|
+
exit: function(record) {
|
7399
|
+
record._inFlightAttributes = {};
|
6645
7400
|
}
|
6646
7401
|
}
|
6647
7402
|
};
|
@@ -6964,7 +7719,11 @@ define("ember-data/lib/system/model/states",
|
|
6964
7719
|
invokeLifecycleCallbacks: function(record) {
|
6965
7720
|
record.triggerLater('didDelete', record);
|
6966
7721
|
record.triggerLater('didCommit', record);
|
6967
|
-
}
|
7722
|
+
},
|
7723
|
+
|
7724
|
+
willCommit: Ember.K,
|
7725
|
+
|
7726
|
+
didCommit: Ember.K
|
6968
7727
|
}
|
6969
7728
|
},
|
6970
7729
|
|
@@ -7008,6 +7767,9 @@ define("ember-data/lib/system/record_array_manager",
|
|
7008
7767
|
@module ember-data
|
7009
7768
|
*/
|
7010
7769
|
|
7770
|
+
var RecordArray = __dependency1__.RecordArray;
|
7771
|
+
var FilteredRecordArray = __dependency1__.FilteredRecordArray;
|
7772
|
+
var AdapterPopulatedRecordArray = __dependency1__.AdapterPopulatedRecordArray;
|
7011
7773
|
var ManyArray = __dependency1__.ManyArray;
|
7012
7774
|
var get = Ember.get, set = Ember.set;
|
7013
7775
|
var forEach = Ember.EnumerableUtils.forEach;
|
@@ -7183,7 +7945,7 @@ define("ember-data/lib/system/record_array_manager",
|
|
7183
7945
|
@return {DS.RecordArray}
|
7184
7946
|
*/
|
7185
7947
|
createRecordArray: function(type) {
|
7186
|
-
var array =
|
7948
|
+
var array = RecordArray.create({
|
7187
7949
|
type: type,
|
7188
7950
|
content: Ember.A(),
|
7189
7951
|
store: this.store,
|
@@ -7201,10 +7963,12 @@ define("ember-data/lib/system/record_array_manager",
|
|
7201
7963
|
@method createFilteredRecordArray
|
7202
7964
|
@param {Class} type
|
7203
7965
|
@param {Function} filter
|
7966
|
+
@param {Object} query (optional
|
7204
7967
|
@return {DS.FilteredRecordArray}
|
7205
7968
|
*/
|
7206
|
-
createFilteredRecordArray: function(type, filter) {
|
7207
|
-
var array =
|
7969
|
+
createFilteredRecordArray: function(type, filter, query) {
|
7970
|
+
var array = FilteredRecordArray.create({
|
7971
|
+
query: query,
|
7208
7972
|
type: type,
|
7209
7973
|
content: Ember.A(),
|
7210
7974
|
store: this.store,
|
@@ -7226,11 +7990,12 @@ define("ember-data/lib/system/record_array_manager",
|
|
7226
7990
|
@return {DS.AdapterPopulatedRecordArray}
|
7227
7991
|
*/
|
7228
7992
|
createAdapterPopulatedRecordArray: function(type, query) {
|
7229
|
-
var array =
|
7993
|
+
var array = AdapterPopulatedRecordArray.create({
|
7230
7994
|
type: type,
|
7231
7995
|
query: query,
|
7232
7996
|
content: Ember.A(),
|
7233
|
-
store: this.store
|
7997
|
+
store: this.store,
|
7998
|
+
manager: this
|
7234
7999
|
});
|
7235
8000
|
|
7236
8001
|
this._adapterPopulatedRecordArrays.push(array);
|
@@ -7270,8 +8035,8 @@ define("ember-data/lib/system/record_array_manager",
|
|
7270
8035
|
willDestroy: function(){
|
7271
8036
|
this._super();
|
7272
8037
|
|
7273
|
-
flatten(values(this.filteredRecordArrays.values))
|
7274
|
-
this._adapterPopulatedRecordArrays
|
8038
|
+
forEach(flatten(values(this.filteredRecordArrays.values)), destroy);
|
8039
|
+
forEach(this._adapterPopulatedRecordArrays, destroy);
|
7275
8040
|
}
|
7276
8041
|
});
|
7277
8042
|
|
@@ -7364,9 +8129,13 @@ define("ember-data/lib/system/record_arrays/adapter_populated_record_array",
|
|
7364
8129
|
this.setProperties({
|
7365
8130
|
content: Ember.A(records),
|
7366
8131
|
isLoaded: true,
|
7367
|
-
meta: meta
|
8132
|
+
meta: Ember.copy(meta)
|
7368
8133
|
});
|
7369
8134
|
|
8135
|
+
records.forEach(function(record) {
|
8136
|
+
this.manager.recordArraysForRecord(record).add(this);
|
8137
|
+
}, this);
|
8138
|
+
|
7370
8139
|
// TODO: should triggering didLoad event be the last action of the runLoop?
|
7371
8140
|
Ember.run.once(this, 'trigger', 'didLoad');
|
7372
8141
|
}
|
@@ -7435,9 +8204,13 @@ define("ember-data/lib/system/record_arrays/filtered_record_array",
|
|
7435
8204
|
@method updateFilter
|
7436
8205
|
@private
|
7437
8206
|
*/
|
7438
|
-
|
8207
|
+
_updateFilter: function() {
|
7439
8208
|
var manager = get(this, 'manager');
|
7440
8209
|
manager.updateFilter(this, get(this, 'type'), get(this, 'filterFunction'));
|
8210
|
+
},
|
8211
|
+
|
8212
|
+
updateFilter: Ember.observer(function() {
|
8213
|
+
Ember.run.once(this, this._updateFilter);
|
7441
8214
|
}, 'filterFunction')
|
7442
8215
|
});
|
7443
8216
|
|
@@ -7568,11 +8341,10 @@ define("ember-data/lib/system/record_arrays/many_array",
|
|
7568
8341
|
fetch: function() {
|
7569
8342
|
var records = get(this, 'content'),
|
7570
8343
|
store = get(this, 'store'),
|
7571
|
-
owner = get(this, 'owner')
|
7572
|
-
resolver = Ember.RSVP.defer("DS: ManyArray#fetch " + get(this, 'type'));
|
8344
|
+
owner = get(this, 'owner');
|
7573
8345
|
|
7574
8346
|
var unloadedRecords = records.filterProperty('isEmpty', true);
|
7575
|
-
store.fetchMany(unloadedRecords, owner
|
8347
|
+
store.fetchMany(unloadedRecords, owner);
|
7576
8348
|
},
|
7577
8349
|
|
7578
8350
|
// Overrides Ember.Array's replace method to implement
|
@@ -7734,7 +8506,7 @@ define("ember-data/lib/system/record_arrays/record_array",
|
|
7734
8506
|
Example
|
7735
8507
|
|
7736
8508
|
```javascript
|
7737
|
-
var people = store.all(
|
8509
|
+
var people = store.all('person');
|
7738
8510
|
people.get('isLoaded'); // true
|
7739
8511
|
```
|
7740
8512
|
|
@@ -7748,7 +8520,7 @@ define("ember-data/lib/system/record_arrays/record_array",
|
|
7748
8520
|
Example
|
7749
8521
|
|
7750
8522
|
```javascript
|
7751
|
-
var people = store.all(
|
8523
|
+
var people = store.all('person');
|
7752
8524
|
people.get('isUpdating'); // false
|
7753
8525
|
people.update();
|
7754
8526
|
people.get('isUpdating'); // true
|
@@ -7789,7 +8561,7 @@ define("ember-data/lib/system/record_arrays/record_array",
|
|
7789
8561
|
Example
|
7790
8562
|
|
7791
8563
|
```javascript
|
7792
|
-
var people = store.all(
|
8564
|
+
var people = store.all('person');
|
7793
8565
|
people.get('isUpdating'); // false
|
7794
8566
|
people.update();
|
7795
8567
|
people.get('isUpdating'); // true
|
@@ -7834,7 +8606,7 @@ define("ember-data/lib/system/record_arrays/record_array",
|
|
7834
8606
|
Example
|
7835
8607
|
|
7836
8608
|
```javascript
|
7837
|
-
var messages = store.all(
|
8609
|
+
var messages = store.all('message');
|
7838
8610
|
messages.forEach(function(message) {
|
7839
8611
|
message.set('hasBeenSeen', true);
|
7840
8612
|
});
|
@@ -7873,6 +8645,41 @@ define("ember-data/lib/system/record_arrays/record_array",
|
|
7873
8645
|
|
7874
8646
|
__exports__["default"] = RecordArray;
|
7875
8647
|
});
|
8648
|
+
define("ember-data/lib/system/relationship-meta",
|
8649
|
+
["../../../ember-inflector/lib/system","exports"],
|
8650
|
+
function(__dependency1__, __exports__) {
|
8651
|
+
"use strict";
|
8652
|
+
var singularize = __dependency1__.singularize;
|
8653
|
+
|
8654
|
+
function typeForRelationshipMeta(store, meta) {
|
8655
|
+
var typeKey, type;
|
8656
|
+
|
8657
|
+
typeKey = meta.type || meta.key;
|
8658
|
+
if (typeof typeKey === 'string') {
|
8659
|
+
if (meta.kind === 'hasMany') {
|
8660
|
+
typeKey = singularize(typeKey);
|
8661
|
+
}
|
8662
|
+
type = store.modelFor(typeKey);
|
8663
|
+
} else {
|
8664
|
+
type = meta.type;
|
8665
|
+
}
|
8666
|
+
|
8667
|
+
return type;
|
8668
|
+
}
|
8669
|
+
|
8670
|
+
__exports__.typeForRelationshipMeta = typeForRelationshipMeta;function relationshipFromMeta(store, meta) {
|
8671
|
+
return {
|
8672
|
+
key: meta.key,
|
8673
|
+
kind: meta.kind,
|
8674
|
+
type: typeForRelationshipMeta(store, meta),
|
8675
|
+
options: meta.options,
|
8676
|
+
parentType: meta.parentType,
|
8677
|
+
isRelationship: true
|
8678
|
+
};
|
8679
|
+
}
|
8680
|
+
|
8681
|
+
__exports__.relationshipFromMeta = relationshipFromMeta;
|
8682
|
+
});
|
7876
8683
|
define("ember-data/lib/system/relationships",
|
7877
8684
|
["./relationships/belongs_to","./relationships/has_many","../system/relationships/ext","exports"],
|
7878
8685
|
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
|
@@ -7889,8 +8696,8 @@ define("ember-data/lib/system/relationships",
|
|
7889
8696
|
__exports__.hasMany = hasMany;
|
7890
8697
|
});
|
7891
8698
|
define("ember-data/lib/system/relationships/belongs_to",
|
7892
|
-
["../model","exports"],
|
7893
|
-
function(__dependency1__, __exports__) {
|
8699
|
+
["../model","../store","../changes","../relationship-meta","exports"],
|
8700
|
+
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) {
|
7894
8701
|
"use strict";
|
7895
8702
|
var get = Ember.get, set = Ember.set,
|
7896
8703
|
isNone = Ember.isNone;
|
@@ -7898,6 +8705,10 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
7898
8705
|
var Promise = Ember.RSVP.Promise;
|
7899
8706
|
|
7900
8707
|
var Model = __dependency1__.Model;
|
8708
|
+
var PromiseObject = __dependency2__.PromiseObject;
|
8709
|
+
var RelationshipChange = __dependency3__.RelationshipChange;
|
8710
|
+
var relationshipFromMeta = __dependency4__.relationshipFromMeta;
|
8711
|
+
var typeForRelationshipMeta = __dependency4__.typeForRelationshipMeta;
|
7901
8712
|
|
7902
8713
|
/**
|
7903
8714
|
@module ember-data
|
@@ -7910,9 +8721,11 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
7910
8721
|
promiseLabel = "DS: Async belongsTo " + this + " : " + key,
|
7911
8722
|
promise;
|
7912
8723
|
|
8724
|
+
meta.key = key;
|
8725
|
+
|
7913
8726
|
if (arguments.length === 2) {
|
7914
|
-
Ember.assert("You can only add a '" + type + "' record to this relationship", !value || value instanceof store
|
7915
|
-
return value === undefined ? null :
|
8727
|
+
Ember.assert("You can only add a '" + type + "' record to this relationship", !value || value instanceof typeForRelationshipMeta(store, meta));
|
8728
|
+
return value === undefined ? null : PromiseObject.create({
|
7916
8729
|
promise: Promise.cast(value, promiseLabel)
|
7917
8730
|
});
|
7918
8731
|
}
|
@@ -7922,12 +8735,12 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
7922
8735
|
|
7923
8736
|
if(!isNone(belongsTo)) {
|
7924
8737
|
promise = store.fetchRecord(belongsTo) || Promise.cast(belongsTo, promiseLabel);
|
7925
|
-
return
|
8738
|
+
return PromiseObject.create({
|
7926
8739
|
promise: promise
|
7927
8740
|
});
|
7928
8741
|
} else if (link) {
|
7929
|
-
promise = store.findBelongsTo(this, link, meta);
|
7930
|
-
return
|
8742
|
+
promise = store.findBelongsTo(this, link, relationshipFromMeta(store, meta));
|
8743
|
+
return PromiseObject.create({
|
7931
8744
|
promise: promise
|
7932
8745
|
});
|
7933
8746
|
} else {
|
@@ -7988,7 +8801,7 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
7988
8801
|
options = type;
|
7989
8802
|
type = undefined;
|
7990
8803
|
} else {
|
7991
|
-
Ember.assert("The first argument DS.belongsTo must be a model type
|
8804
|
+
Ember.assert("The first argument to DS.belongsTo must be a string representing a model type key, e.g. use DS.belongsTo('person') to define a relation to the App.Person model", !!type && (typeof type === 'string' || Model.detect(type)));
|
7992
8805
|
}
|
7993
8806
|
|
7994
8807
|
options = options || {};
|
@@ -7997,7 +8810,8 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
7997
8810
|
type: type,
|
7998
8811
|
isRelationship: true,
|
7999
8812
|
options: options,
|
8000
|
-
kind: 'belongsTo'
|
8813
|
+
kind: 'belongsTo',
|
8814
|
+
key: null
|
8001
8815
|
};
|
8002
8816
|
|
8003
8817
|
if (options.async) {
|
@@ -8051,7 +8865,7 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
8051
8865
|
|
8052
8866
|
if (oldParent) {
|
8053
8867
|
var store = get(record, 'store'),
|
8054
|
-
change =
|
8868
|
+
change = RelationshipChange.createChange(record, oldParent, store, { key: key, kind: "belongsTo", changeType: "remove" });
|
8055
8869
|
|
8056
8870
|
change.sync();
|
8057
8871
|
this._changesToSync[key] = change;
|
@@ -8072,7 +8886,7 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
8072
8886
|
|
8073
8887
|
if (newParent) {
|
8074
8888
|
var store = get(record, 'store'),
|
8075
|
-
change =
|
8889
|
+
change = RelationshipChange.createChange(record, newParent, store, { key: key, kind: "belongsTo", changeType: "add" });
|
8076
8890
|
|
8077
8891
|
change.sync();
|
8078
8892
|
}
|
@@ -8085,11 +8899,13 @@ define("ember-data/lib/system/relationships/belongs_to",
|
|
8085
8899
|
__exports__["default"] = belongsTo;
|
8086
8900
|
});
|
8087
8901
|
define("ember-data/lib/system/relationships/ext",
|
8088
|
-
["../../../../ember-inflector/lib/system","../model"],
|
8089
|
-
function(__dependency1__, __dependency2__) {
|
8902
|
+
["../../../../ember-inflector/lib/system","../relationship-meta","../model"],
|
8903
|
+
function(__dependency1__, __dependency2__, __dependency3__) {
|
8090
8904
|
"use strict";
|
8091
8905
|
var singularize = __dependency1__.singularize;
|
8092
|
-
var
|
8906
|
+
var typeForRelationshipMeta = __dependency2__.typeForRelationshipMeta;
|
8907
|
+
var relationshipFromMeta = __dependency2__.relationshipFromMeta;
|
8908
|
+
var Model = __dependency3__.Model;
|
8093
8909
|
|
8094
8910
|
var get = Ember.get, set = Ember.set;
|
8095
8911
|
|
@@ -8288,18 +9104,15 @@ define("ember-data/lib/system/relationships/ext",
|
|
8288
9104
|
// If the computed property is a relationship, add
|
8289
9105
|
// it to the map.
|
8290
9106
|
if (meta.isRelationship) {
|
8291
|
-
|
8292
|
-
|
8293
|
-
}
|
8294
|
-
|
8295
|
-
var relationshipsForType = map.get(meta.type);
|
9107
|
+
meta.key = name;
|
9108
|
+
var relationshipsForType = map.get(typeForRelationshipMeta(this.store, meta));
|
8296
9109
|
|
8297
9110
|
relationshipsForType.push({ name: name, kind: meta.kind });
|
8298
9111
|
}
|
8299
9112
|
});
|
8300
9113
|
|
8301
9114
|
return map;
|
8302
|
-
}),
|
9115
|
+
}).cacheable(false),
|
8303
9116
|
|
8304
9117
|
/**
|
8305
9118
|
A hash containing lists of the model's relationships, grouped
|
@@ -8379,11 +9192,8 @@ define("ember-data/lib/system/relationships/ext",
|
|
8379
9192
|
// in relationships
|
8380
9193
|
this.eachComputedProperty(function(name, meta) {
|
8381
9194
|
if (meta.isRelationship) {
|
8382
|
-
|
8383
|
-
|
8384
|
-
if (typeof type === 'string') {
|
8385
|
-
type = get(this, type, false) || this.store.modelFor(type);
|
8386
|
-
}
|
9195
|
+
meta.key = name;
|
9196
|
+
type = typeForRelationshipMeta(this.store, meta);
|
8387
9197
|
|
8388
9198
|
Ember.assert("You specified a hasMany (" + meta.type + ") on " + meta.parentType + " but " + meta.type + " was not found.", type);
|
8389
9199
|
|
@@ -8395,7 +9205,7 @@ define("ember-data/lib/system/relationships/ext",
|
|
8395
9205
|
});
|
8396
9206
|
|
8397
9207
|
return types;
|
8398
|
-
}),
|
9208
|
+
}).cacheable(false),
|
8399
9209
|
|
8400
9210
|
/**
|
8401
9211
|
A map whose keys are the relationships of a model and whose values are
|
@@ -8429,29 +9239,19 @@ define("ember-data/lib/system/relationships/ext",
|
|
8429
9239
|
@readOnly
|
8430
9240
|
*/
|
8431
9241
|
relationshipsByName: Ember.computed(function() {
|
8432
|
-
var map = Ember.Map.create()
|
9242
|
+
var map = Ember.Map.create();
|
8433
9243
|
|
8434
9244
|
this.eachComputedProperty(function(name, meta) {
|
8435
9245
|
if (meta.isRelationship) {
|
8436
9246
|
meta.key = name;
|
8437
|
-
|
8438
|
-
|
8439
|
-
|
8440
|
-
type = singularize(name);
|
8441
|
-
} else if (!type) {
|
8442
|
-
type = name;
|
8443
|
-
}
|
8444
|
-
|
8445
|
-
if (typeof type === 'string') {
|
8446
|
-
meta.type = this.store.modelFor(type);
|
8447
|
-
}
|
8448
|
-
|
8449
|
-
map.set(name, meta);
|
9247
|
+
var relationship = relationshipFromMeta(this.store, meta);
|
9248
|
+
relationship.type = typeForRelationshipMeta(this.store, meta);
|
9249
|
+
map.set(name, relationship);
|
8450
9250
|
}
|
8451
9251
|
});
|
8452
9252
|
|
8453
9253
|
return map;
|
8454
|
-
}),
|
9254
|
+
}).cacheable(false),
|
8455
9255
|
|
8456
9256
|
/**
|
8457
9257
|
A map whose keys are the fields of the model and whose values are strings
|
@@ -8552,29 +9352,34 @@ define("ember-data/lib/system/relationships/ext",
|
|
8552
9352
|
});
|
8553
9353
|
});
|
8554
9354
|
define("ember-data/lib/system/relationships/has_many",
|
8555
|
-
["exports"],
|
8556
|
-
function(__exports__) {
|
9355
|
+
["../store","../relationship-meta","exports"],
|
9356
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
8557
9357
|
"use strict";
|
8558
9358
|
/**
|
8559
9359
|
@module ember-data
|
8560
9360
|
*/
|
8561
9361
|
|
9362
|
+
var PromiseArray = __dependency1__.PromiseArray;
|
8562
9363
|
var get = Ember.get, set = Ember.set, setProperties = Ember.setProperties;
|
9364
|
+
var relationshipFromMeta = __dependency2__.relationshipFromMeta;
|
9365
|
+
var typeForRelationshipMeta = __dependency2__.typeForRelationshipMeta;
|
8563
9366
|
|
8564
9367
|
function asyncHasMany(type, options, meta) {
|
8565
9368
|
return Ember.computed('data', function(key) {
|
8566
9369
|
var relationship = this._relationships[key],
|
8567
9370
|
promiseLabel = "DS: Async hasMany " + this + " : " + key;
|
8568
9371
|
|
9372
|
+
meta.key = key;
|
9373
|
+
|
8569
9374
|
if (!relationship) {
|
8570
9375
|
var resolver = Ember.RSVP.defer(promiseLabel);
|
8571
9376
|
relationship = buildRelationship(this, key, options, function(store, data) {
|
8572
9377
|
var link = data.links && data.links[key];
|
8573
9378
|
var rel;
|
8574
9379
|
if (link) {
|
8575
|
-
rel = store.findHasMany(this, link, meta, resolver);
|
9380
|
+
rel = store.findHasMany(this, link, relationshipFromMeta(store, meta), resolver);
|
8576
9381
|
} else {
|
8577
|
-
rel = store.findMany(this, data[key], meta
|
9382
|
+
rel = store.findMany(this, data[key], typeForRelationshipMeta(store, meta), resolver);
|
8578
9383
|
}
|
8579
9384
|
// cache the promise so we can use it
|
8580
9385
|
// when we come back and don't need to rebuild
|
@@ -8588,7 +9393,7 @@ define("ember-data/lib/system/relationships/has_many",
|
|
8588
9393
|
return relationship;
|
8589
9394
|
}, null, "DS: Async hasMany records received");
|
8590
9395
|
|
8591
|
-
return
|
9396
|
+
return PromiseArray.create({
|
8592
9397
|
promise: promise
|
8593
9398
|
});
|
8594
9399
|
}).meta(meta).readOnly();
|
@@ -8618,7 +9423,8 @@ define("ember-data/lib/system/relationships/has_many",
|
|
8618
9423
|
type: type,
|
8619
9424
|
isRelationship: true,
|
8620
9425
|
options: options,
|
8621
|
-
kind: 'hasMany'
|
9426
|
+
kind: 'hasMany',
|
9427
|
+
key: null
|
8622
9428
|
};
|
8623
9429
|
|
8624
9430
|
if (options.async) {
|
@@ -8629,7 +9435,7 @@ define("ember-data/lib/system/relationships/has_many",
|
|
8629
9435
|
return buildRelationship(this, key, options, function(store, data) {
|
8630
9436
|
var records = data[key];
|
8631
9437
|
Ember.assert("You looked up the '" + key + "' relationship on '" + this + "' but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (`DS.hasMany({ async: true })`)", Ember.A(records).everyProperty('isEmpty', false));
|
8632
|
-
return store.findMany(this, data[key], meta
|
9438
|
+
return store.findMany(this, data[key], typeForRelationshipMeta(store, meta));
|
8633
9439
|
});
|
8634
9440
|
}).meta(meta).readOnly();
|
8635
9441
|
}
|
@@ -8723,8 +9529,8 @@ define("ember-data/lib/system/relationships/has_many",
|
|
8723
9529
|
__exports__["default"] = hasMany;
|
8724
9530
|
});
|
8725
9531
|
define("ember-data/lib/system/store",
|
8726
|
-
["exports"],
|
8727
|
-
function(__exports__) {
|
9532
|
+
["./adapter","ember-inflector/lib/system/string","exports"],
|
9533
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
8728
9534
|
"use strict";
|
8729
9535
|
/*globals Ember*/
|
8730
9536
|
/*jshint eqnull:true*/
|
@@ -8733,6 +9539,9 @@ define("ember-data/lib/system/store",
|
|
8733
9539
|
@module ember-data
|
8734
9540
|
*/
|
8735
9541
|
|
9542
|
+
var InvalidError = __dependency1__.InvalidError;
|
9543
|
+
var Adapter = __dependency1__.Adapter;
|
9544
|
+
var singularize = __dependency2__.singularize;
|
8736
9545
|
var get = Ember.get, set = Ember.set;
|
8737
9546
|
var once = Ember.run.once;
|
8738
9547
|
var isNone = Ember.isNone;
|
@@ -8741,7 +9550,9 @@ define("ember-data/lib/system/store",
|
|
8741
9550
|
var map = Ember.EnumerableUtils.map;
|
8742
9551
|
var Promise = Ember.RSVP.Promise;
|
8743
9552
|
var copy = Ember.copy;
|
8744
|
-
var Store, PromiseObject, PromiseArray;
|
9553
|
+
var Store, PromiseObject, PromiseArray, RecordArrayManager, Model;
|
9554
|
+
|
9555
|
+
var camelize = Ember.String.camelize;
|
8745
9556
|
|
8746
9557
|
// Implementors Note:
|
8747
9558
|
//
|
@@ -8794,7 +9605,7 @@ define("ember-data/lib/system/store",
|
|
8794
9605
|
specify which store should be used:
|
8795
9606
|
|
8796
9607
|
```javascript
|
8797
|
-
var person = store.find(
|
9608
|
+
var person = store.find('person', 123);
|
8798
9609
|
```
|
8799
9610
|
|
8800
9611
|
By default, the store will talk to your backend using a standard
|
@@ -8810,6 +9621,39 @@ define("ember-data/lib/system/store",
|
|
8810
9621
|
You can learn more about writing a custom adapter by reading the `DS.Adapter`
|
8811
9622
|
documentation.
|
8812
9623
|
|
9624
|
+
### Store createRecord() vs. push() vs. pushPayload() vs. update()
|
9625
|
+
|
9626
|
+
The store provides multiple ways to create new records object. They have
|
9627
|
+
some subtle differences in their use which are detailed below:
|
9628
|
+
|
9629
|
+
[createRecord](#method_createRecord) is used for creating new
|
9630
|
+
records on the client side. This will return a new record in the
|
9631
|
+
`created.uncommitted` state. In order to persist this record to the
|
9632
|
+
backend you will need to call `record.save()`.
|
9633
|
+
|
9634
|
+
[push](#method_push) is used to notify Ember Data's store of new or
|
9635
|
+
updated records that exist in the backend. This will return a record
|
9636
|
+
in the `loaded.saved` state. The primary use-case for `store#push` is
|
9637
|
+
to notify Ember Data about record updates that happen
|
9638
|
+
outside of the normal adapter methods (for example
|
9639
|
+
[SSE](http://dev.w3.org/html5/eventsource/) or [Web
|
9640
|
+
Sockets](http://www.w3.org/TR/2009/WD-websockets-20091222/)).
|
9641
|
+
|
9642
|
+
[pushPayload](#method_pushPayload) is a convenience wrapper for
|
9643
|
+
`store#push` that will deserialize payloads if the
|
9644
|
+
Serializer implements a `pushPayload` method.
|
9645
|
+
|
9646
|
+
[update](#method_update) works like `push`, except it can handle
|
9647
|
+
partial attributes without overwriting the existing record
|
9648
|
+
properties.
|
9649
|
+
|
9650
|
+
Note: When creating a new record using any of the above methods
|
9651
|
+
Ember Data will update `DS.RecordArray`s such as those returned by
|
9652
|
+
`store#all()`, `store#findAll()` or `store#filter()`. This means any
|
9653
|
+
data bindings or computed properties that depend on the RecordArray
|
9654
|
+
will automatically be synced to include the new or updated record
|
9655
|
+
values.
|
9656
|
+
|
8813
9657
|
@class Store
|
8814
9658
|
@namespace DS
|
8815
9659
|
@extends Ember.Object
|
@@ -8822,8 +9666,9 @@ define("ember-data/lib/system/store",
|
|
8822
9666
|
*/
|
8823
9667
|
init: function() {
|
8824
9668
|
// internal bookkeeping; not observable
|
9669
|
+
if (!RecordArrayManager) { RecordArrayManager = requireModule("ember-data/lib/system/record_array_manager")["default"]; }
|
8825
9670
|
this.typeMaps = {};
|
8826
|
-
this.recordArrayManager =
|
9671
|
+
this.recordArrayManager = RecordArrayManager.create({
|
8827
9672
|
store: this
|
8828
9673
|
});
|
8829
9674
|
this._relationshipChanges = {};
|
@@ -8878,12 +9723,12 @@ define("ember-data/lib/system/store",
|
|
8878
9723
|
|
8879
9724
|
@property defaultAdapter
|
8880
9725
|
@private
|
8881
|
-
@
|
9726
|
+
@return DS.Adapter
|
8882
9727
|
*/
|
8883
9728
|
defaultAdapter: Ember.computed('adapter', function() {
|
8884
9729
|
var adapter = get(this, 'adapter');
|
8885
9730
|
|
8886
|
-
Ember.assert('You tried to set `adapter` property to an instance of `DS.Adapter`, where it should be a name or a factory', !(adapter instanceof
|
9731
|
+
Ember.assert('You tried to set `adapter` property to an instance of `DS.Adapter`, where it should be a name or a factory', !(adapter instanceof Adapter));
|
8887
9732
|
|
8888
9733
|
if (typeof adapter === 'string') {
|
8889
9734
|
adapter = this.container.lookup('adapter:' + adapter) || this.container.lookup('adapter:application') || this.container.lookup('adapter:-rest');
|
@@ -8918,7 +9763,7 @@ define("ember-data/lib/system/store",
|
|
8918
9763
|
@param {String} type
|
8919
9764
|
@param {Object} properties a hash of properties to set on the
|
8920
9765
|
newly created record.
|
8921
|
-
@
|
9766
|
+
@return {DS.Model} record
|
8922
9767
|
*/
|
8923
9768
|
createRecord: function(type, properties) {
|
8924
9769
|
type = this.modelFor(type);
|
@@ -8956,7 +9801,7 @@ define("ember-data/lib/system/store",
|
|
8956
9801
|
@method _generateId
|
8957
9802
|
@private
|
8958
9803
|
@param {String} type
|
8959
|
-
@
|
9804
|
+
@return {String} if the adapter can generate one, an ID
|
8960
9805
|
*/
|
8961
9806
|
_generateId: function(type) {
|
8962
9807
|
var adapter = this.adapterFor(type);
|
@@ -9053,7 +9898,7 @@ define("ember-data/lib/system/store",
|
|
9053
9898
|
parameter:
|
9054
9899
|
|
9055
9900
|
```javascript
|
9056
|
-
store.find(
|
9901
|
+
store.find('person', { page: 1 });
|
9057
9902
|
```
|
9058
9903
|
|
9059
9904
|
This will ask the adapter's `findQuery` method to find the records for
|
@@ -9107,7 +9952,7 @@ define("ember-data/lib/system/store",
|
|
9107
9952
|
@method findByIds
|
9108
9953
|
@param {String} type
|
9109
9954
|
@param {Array} ids
|
9110
|
-
@
|
9955
|
+
@return {Promise} promise
|
9111
9956
|
*/
|
9112
9957
|
findByIds: function(type, ids) {
|
9113
9958
|
var store = this;
|
@@ -9125,7 +9970,7 @@ define("ember-data/lib/system/store",
|
|
9125
9970
|
@method fetchRecord
|
9126
9971
|
@private
|
9127
9972
|
@param {DS.Model} record
|
9128
|
-
@
|
9973
|
+
@return {Promise} promise
|
9129
9974
|
*/
|
9130
9975
|
fetchRecord: function(record) {
|
9131
9976
|
if (isNone(record)) { return null; }
|
@@ -9211,7 +10056,9 @@ define("ember-data/lib/system/store",
|
|
9211
10056
|
@return {Promise} promise
|
9212
10057
|
*/
|
9213
10058
|
fetchMany: function(records, owner) {
|
9214
|
-
if (!records.length) {
|
10059
|
+
if (!records.length) {
|
10060
|
+
return Ember.RSVP.resolve(records);
|
10061
|
+
}
|
9215
10062
|
|
9216
10063
|
// Group By Type
|
9217
10064
|
var recordsByTypeMap = Ember.MapWithDefault.create({
|
@@ -9243,7 +10090,7 @@ define("ember-data/lib/system/store",
|
|
9243
10090
|
@method hasRecordForId
|
9244
10091
|
@param {String or subclass of DS.Model} type
|
9245
10092
|
@param {String|Integer} id
|
9246
|
-
@
|
10093
|
+
@return {Boolean}
|
9247
10094
|
*/
|
9248
10095
|
hasRecordForId: function(type, id) {
|
9249
10096
|
id = coerceId(id);
|
@@ -9259,7 +10106,7 @@ define("ember-data/lib/system/store",
|
|
9259
10106
|
@private
|
9260
10107
|
@param {String or subclass of DS.Model} type
|
9261
10108
|
@param {String|Integer} id
|
9262
|
-
@
|
10109
|
+
@return {DS.Model} record
|
9263
10110
|
*/
|
9264
10111
|
recordForId: function(type, id) {
|
9265
10112
|
type = this.modelFor(type);
|
@@ -9411,7 +10258,7 @@ define("ember-data/lib/system/store",
|
|
9411
10258
|
@private
|
9412
10259
|
@param {DS.Model} type
|
9413
10260
|
@param {DS.RecordArray} array
|
9414
|
-
@
|
10261
|
+
@return {Promise} promise
|
9415
10262
|
*/
|
9416
10263
|
fetchAll: function(type, array) {
|
9417
10264
|
var adapter = this.adapterFor(type),
|
@@ -9447,7 +10294,7 @@ define("ember-data/lib/system/store",
|
|
9447
10294
|
Example
|
9448
10295
|
|
9449
10296
|
```javascript
|
9450
|
-
var
|
10297
|
+
var localPosts = store.all('post');
|
9451
10298
|
```
|
9452
10299
|
|
9453
10300
|
@method all
|
@@ -9473,7 +10320,7 @@ define("ember-data/lib/system/store",
|
|
9473
10320
|
This method unloads all of the known records for a given type.
|
9474
10321
|
|
9475
10322
|
```javascript
|
9476
|
-
store.unloadAll(
|
10323
|
+
store.unloadAll('post');
|
9477
10324
|
```
|
9478
10325
|
|
9479
10326
|
@method unloadAll
|
@@ -9517,7 +10364,7 @@ define("ember-data/lib/system/store",
|
|
9517
10364
|
Example
|
9518
10365
|
|
9519
10366
|
```javascript
|
9520
|
-
store.filter(
|
10367
|
+
store.filter('post', {unread: true}, function(post) {
|
9521
10368
|
return post.get('unread');
|
9522
10369
|
}).then(function(unreadPosts) {
|
9523
10370
|
unreadPosts.get('length'); // 5
|
@@ -9535,9 +10382,12 @@ define("ember-data/lib/system/store",
|
|
9535
10382
|
*/
|
9536
10383
|
filter: function(type, query, filter) {
|
9537
10384
|
var promise;
|
10385
|
+
var length = arguments.length;
|
10386
|
+
var array;
|
10387
|
+
var hasQuery = length === 3;
|
9538
10388
|
|
9539
10389
|
// allow an optional server query
|
9540
|
-
if (
|
10390
|
+
if (hasQuery) {
|
9541
10391
|
promise = this.findQuery(type, query);
|
9542
10392
|
} else if (arguments.length === 2) {
|
9543
10393
|
filter = query;
|
@@ -9545,10 +10395,15 @@ define("ember-data/lib/system/store",
|
|
9545
10395
|
|
9546
10396
|
type = this.modelFor(type);
|
9547
10397
|
|
9548
|
-
|
9549
|
-
.createFilteredRecordArray(type, filter);
|
10398
|
+
if (hasQuery) {
|
10399
|
+
array = this.recordArrayManager.createFilteredRecordArray(type, filter, query);
|
10400
|
+
} else {
|
10401
|
+
array = this.recordArrayManager.createFilteredRecordArray(type, filter);
|
10402
|
+
}
|
10403
|
+
|
9550
10404
|
promise = promise || Promise.cast(array);
|
9551
10405
|
|
10406
|
+
|
9552
10407
|
return promiseArray(promise.then(function() {
|
9553
10408
|
return array;
|
9554
10409
|
}, null, "DS: Store#filter of " + type));
|
@@ -9562,9 +10417,9 @@ define("ember-data/lib/system/store",
|
|
9562
10417
|
Example
|
9563
10418
|
|
9564
10419
|
```javascript
|
9565
|
-
store.recordIsLoaded(
|
9566
|
-
store.find(
|
9567
|
-
store.recordIsLoaded(
|
10420
|
+
store.recordIsLoaded('post', 1); // false
|
10421
|
+
store.find('post', 1).then(function() {
|
10422
|
+
store.recordIsLoaded('post', 1); // true
|
9568
10423
|
});
|
9569
10424
|
```
|
9570
10425
|
|
@@ -9648,7 +10503,9 @@ define("ember-data/lib/system/store",
|
|
9648
10503
|
adapter = this.adapterFor(record.constructor),
|
9649
10504
|
operation;
|
9650
10505
|
|
9651
|
-
if (get(record, '
|
10506
|
+
if (get(record, 'currentState.stateName') === 'root.deleted.saved') {
|
10507
|
+
return resolver.resolve(record);
|
10508
|
+
} else if (get(record, 'isNew')) {
|
9652
10509
|
operation = 'createRecord';
|
9653
10510
|
} else if (get(record, 'isDeleted')) {
|
9654
10511
|
operation = 'deleteRecord';
|
@@ -9792,7 +10649,7 @@ define("ember-data/lib/system/store",
|
|
9792
10649
|
|
9793
10650
|
@method modelFor
|
9794
10651
|
@param {String or subclass of DS.Model} key
|
9795
|
-
@
|
10652
|
+
@return {subclass of DS.Model}
|
9796
10653
|
*/
|
9797
10654
|
modelFor: function(key) {
|
9798
10655
|
var factory;
|
@@ -9803,10 +10660,13 @@ define("ember-data/lib/system/store",
|
|
9803
10660
|
|
9804
10661
|
factory = this.container.lookupFactory(normalizedKey);
|
9805
10662
|
if (!factory) { throw new Ember.Error("No model was found for '" + key + "'"); }
|
9806
|
-
factory.typeKey = normalizedKey.split(':', 2)[1];
|
10663
|
+
factory.typeKey = this._normalizeTypeKey(normalizedKey.split(':', 2)[1]);
|
9807
10664
|
} else {
|
9808
|
-
// A factory already supplied.
|
10665
|
+
// A factory already supplied. Ensure it has a normalized key.
|
9809
10666
|
factory = key;
|
10667
|
+
if (factory.typeKey) {
|
10668
|
+
factory.typeKey = this._normalizeTypeKey(factory.typeKey);
|
10669
|
+
}
|
9810
10670
|
}
|
9811
10671
|
|
9812
10672
|
factory.store = this;
|
@@ -9871,7 +10731,7 @@ define("ember-data/lib/system/store",
|
|
9871
10731
|
@method push
|
9872
10732
|
@param {String or subclass of DS.Model} type
|
9873
10733
|
@param {Object} data
|
9874
|
-
@
|
10734
|
+
@return {DS.Model} the record that was created or
|
9875
10735
|
updated.
|
9876
10736
|
*/
|
9877
10737
|
push: function(type, data, _partial) {
|
@@ -9879,7 +10739,7 @@ define("ember-data/lib/system/store",
|
|
9879
10739
|
// If passed, it means that the data should be
|
9880
10740
|
// merged into the existing data, not replace it.
|
9881
10741
|
|
9882
|
-
Ember.assert("You must include an `id` in a hash passed to `push`", data.id != null);
|
10742
|
+
Ember.assert("You must include an `id` for " + type + " in a hash passed to `push`", data.id != null);
|
9883
10743
|
|
9884
10744
|
type = this.modelFor(type);
|
9885
10745
|
|
@@ -9894,13 +10754,9 @@ define("ember-data/lib/system/store",
|
|
9894
10754
|
/**
|
9895
10755
|
Push some raw data into the store.
|
9896
10756
|
|
9897
|
-
The data will be automatically deserialized using the
|
9898
|
-
serializer for the `type` param.
|
9899
|
-
|
9900
10757
|
This method can be used both to push in brand new
|
9901
|
-
records, as well as to update existing records.
|
9902
|
-
|
9903
|
-
You can push in more than one type of object at once.
|
10758
|
+
records, as well as to update existing records. You
|
10759
|
+
can push in more than one type of object at once.
|
9904
10760
|
All objects should be in the format expected by the
|
9905
10761
|
serializer.
|
9906
10762
|
|
@@ -9916,11 +10772,27 @@ define("ember-data/lib/system/store",
|
|
9916
10772
|
]
|
9917
10773
|
}
|
9918
10774
|
|
9919
|
-
store.pushPayload(
|
10775
|
+
store.pushPayload(pushData);
|
10776
|
+
```
|
10777
|
+
|
10778
|
+
By default, the data will be deserialized using a default
|
10779
|
+
serializer (the application serializer if it exists).
|
10780
|
+
|
10781
|
+
Alternativly, `pushPayload` will accept a model type which
|
10782
|
+
will determine which serializer will process the payload.
|
10783
|
+
However, the serializer itself (processing this data via
|
10784
|
+
`normalizePayload`) will not know which model it is
|
10785
|
+
deserializing.
|
10786
|
+
|
10787
|
+
```js
|
10788
|
+
App.ApplicationSerializer = DS.ActiveModelSerializer;
|
10789
|
+
App.PostSerializer = DS.JSONSerializer;
|
10790
|
+
store.pushPayload('comment', pushData); // Will use the ApplicationSerializer
|
10791
|
+
store.pushPayload('post', pushData); // Will use the PostSerializer
|
9920
10792
|
```
|
9921
10793
|
|
9922
10794
|
@method pushPayload
|
9923
|
-
@param {String} type
|
10795
|
+
@param {String} type Optionally, a model used to determine which serializer will be used
|
9924
10796
|
@param {Object} payload
|
9925
10797
|
*/
|
9926
10798
|
pushPayload: function (type, payload) {
|
@@ -9935,8 +10807,40 @@ define("ember-data/lib/system/store",
|
|
9935
10807
|
serializer.pushPayload(this, payload);
|
9936
10808
|
},
|
9937
10809
|
|
10810
|
+
/**
|
10811
|
+
Update existing records in the store. Unlike [push](#method_push),
|
10812
|
+
update will merge the new data properties with the existing
|
10813
|
+
properties. This makes it safe to use with a subset of record
|
10814
|
+
attributes. This method expects normalized data.
|
10815
|
+
|
10816
|
+
`update` is useful if you app broadcasts partial updates to
|
10817
|
+
records.
|
10818
|
+
|
10819
|
+
```js
|
10820
|
+
App.Person = DS.Model.extend({
|
10821
|
+
firstName: DS.attr('string'),
|
10822
|
+
lastName: DS.attr('string')
|
10823
|
+
});
|
10824
|
+
|
10825
|
+
store.get('person', 1).then(function(tom) {
|
10826
|
+
tom.get('firstName'); // Tom
|
10827
|
+
tom.get('lastName'); // Dale
|
10828
|
+
|
10829
|
+
var updateEvent = {id: 1, firstName: "TomHuda"};
|
10830
|
+
store.update('person', updateEvent);
|
10831
|
+
|
10832
|
+
tom.get('firstName'); // TomHuda
|
10833
|
+
tom.get('lastName'); // Dale
|
10834
|
+
});
|
10835
|
+
```
|
10836
|
+
|
10837
|
+
@method update
|
10838
|
+
@param {String} type
|
10839
|
+
@param {Object} data
|
10840
|
+
@return {DS.Model} the record that was updated.
|
10841
|
+
*/
|
9938
10842
|
update: function(type, data) {
|
9939
|
-
Ember.assert("You must include an `id` in a hash passed to `update`", data.id != null);
|
10843
|
+
Ember.assert("You must include an `id` for " + type + " in a hash passed to `update`", data.id != null);
|
9940
10844
|
|
9941
10845
|
return this.push(type, data, true);
|
9942
10846
|
},
|
@@ -9980,7 +10884,7 @@ define("ember-data/lib/system/store",
|
|
9980
10884
|
@param {subclass of DS.Model} type
|
9981
10885
|
@param {String} id
|
9982
10886
|
@param {Object} data
|
9983
|
-
@
|
10887
|
+
@return {DS.Model} record
|
9984
10888
|
*/
|
9985
10889
|
buildRecord: function(type, id, data) {
|
9986
10890
|
var typeMap = this.typeMapFor(type),
|
@@ -10100,7 +11004,7 @@ define("ember-data/lib/system/store",
|
|
10100
11004
|
@method adapterFor
|
10101
11005
|
@private
|
10102
11006
|
@param {subclass of DS.Model} type
|
10103
|
-
@
|
11007
|
+
@return DS.Adapter
|
10104
11008
|
*/
|
10105
11009
|
adapterFor: function(type) {
|
10106
11010
|
var container = this.container, adapter;
|
@@ -10141,18 +11045,33 @@ define("ember-data/lib/system/store",
|
|
10141
11045
|
},
|
10142
11046
|
|
10143
11047
|
willDestroy: function() {
|
10144
|
-
var
|
10145
|
-
var keys = Ember.keys(
|
11048
|
+
var typeMaps = this.typeMaps;
|
11049
|
+
var keys = Ember.keys(typeMaps);
|
10146
11050
|
var store = this;
|
10147
|
-
|
11051
|
+
|
11052
|
+
var types = map(keys, byType);
|
10148
11053
|
|
10149
11054
|
this.recordArrayManager.destroy();
|
10150
11055
|
|
10151
|
-
|
11056
|
+
forEach(types, this.unloadAll, this);
|
10152
11057
|
|
10153
11058
|
function byType(entry) {
|
10154
|
-
return
|
11059
|
+
return typeMaps[entry]['type'];
|
10155
11060
|
}
|
11061
|
+
|
11062
|
+
},
|
11063
|
+
|
11064
|
+
/**
|
11065
|
+
All typeKeys are camelCase internally. Changing this function may
|
11066
|
+
require changes to other normalization hooks (such as typeForRoot).
|
11067
|
+
|
11068
|
+
@method _normalizeTypeKey
|
11069
|
+
@private
|
11070
|
+
@param {String} type
|
11071
|
+
@return {String} if the adapter can generate one, an ID
|
11072
|
+
*/
|
11073
|
+
_normalizeTypeKey: function(key) {
|
11074
|
+
return camelize(singularize(key));
|
10156
11075
|
}
|
10157
11076
|
});
|
10158
11077
|
|
@@ -10182,7 +11101,8 @@ define("ember-data/lib/system/store",
|
|
10182
11101
|
}
|
10183
11102
|
|
10184
11103
|
function deserializeRecordId(store, data, key, relationship, id) {
|
10185
|
-
if (
|
11104
|
+
if (!Model) { Model = requireModule("ember-data/lib/system/model")["Model"]; }
|
11105
|
+
if (isNone(id) || id instanceof Model) {
|
10186
11106
|
return;
|
10187
11107
|
}
|
10188
11108
|
|
@@ -10215,14 +11135,14 @@ define("ember-data/lib/system/store",
|
|
10215
11135
|
// in the payload, so add them back in manually.
|
10216
11136
|
function addUnsavedRecords(record, key, data) {
|
10217
11137
|
if(record) {
|
10218
|
-
data.pushObjects(record.get(key).filterBy('isNew'));
|
11138
|
+
Ember.A(data).pushObjects(record.get(key).filterBy('isNew'));
|
10219
11139
|
}
|
10220
11140
|
}
|
10221
11141
|
|
10222
11142
|
// Delegation to the adapter and promise management
|
10223
11143
|
/**
|
10224
11144
|
A `PromiseArray` is an object that acts like both an `Ember.Array`
|
10225
|
-
and a promise. When the promise is resolved the
|
11145
|
+
and a promise. When the promise is resolved the resulting value
|
10226
11146
|
will be set to the `PromiseArray`'s `content` property. This makes
|
10227
11147
|
it easy to create data bindings with the `PromiseArray` that will be
|
10228
11148
|
updated when the promise resolves.
|
@@ -10438,7 +11358,7 @@ define("ember-data/lib/system/store",
|
|
10438
11358
|
store.didSaveRecord(record, payload);
|
10439
11359
|
return record;
|
10440
11360
|
}, function(reason) {
|
10441
|
-
if (reason instanceof
|
11361
|
+
if (reason instanceof InvalidError) {
|
10442
11362
|
store.recordWasInvalid(record, reason.errors);
|
10443
11363
|
} else {
|
10444
11364
|
store.recordWasError(record, reason);
|
@@ -10483,12 +11403,13 @@ define("ember-data/lib/transforms/base",
|
|
10483
11403
|
Example
|
10484
11404
|
|
10485
11405
|
```javascript
|
10486
|
-
|
11406
|
+
// Converts centigrade in the JSON to fahrenheit in the app
|
11407
|
+
App.TemperatureTransform = DS.Transform.extend({
|
10487
11408
|
deserialize: function(serialized) {
|
10488
|
-
return serialized;
|
11409
|
+
return (serialized * 1.8) + 32;
|
10489
11410
|
},
|
10490
11411
|
serialize: function(deserialized) {
|
10491
|
-
return deserialized;
|
11412
|
+
return (deserialized - 32) / 1.8;
|
10492
11413
|
}
|
10493
11414
|
});
|
10494
11415
|
```
|
@@ -10788,11 +11709,11 @@ define("ember-inflector/lib/main",
|
|
10788
11709
|
function(__dependency1__, __dependency2__, __exports__) {
|
10789
11710
|
"use strict";
|
10790
11711
|
var Inflector = __dependency1__.Inflector;
|
10791
|
-
var
|
11712
|
+
var defaultRules = __dependency1__.defaultRules;
|
10792
11713
|
var pluralize = __dependency1__.pluralize;
|
10793
11714
|
var singularize = __dependency1__.singularize;
|
10794
11715
|
|
10795
|
-
Inflector.defaultRules =
|
11716
|
+
Inflector.defaultRules = defaultRules;
|
10796
11717
|
Ember.Inflector = Inflector;
|
10797
11718
|
|
10798
11719
|
Ember.String.pluralize = pluralize;
|
@@ -10949,8 +11870,8 @@ define("ember-inflector/lib/system/inflector",
|
|
10949
11870
|
```js
|
10950
11871
|
var inflector = new Ember.Inflector(Ember.Inflector.defaultRules);
|
10951
11872
|
|
10952
|
-
inflector.pluralize('cow') //=> 'kine'
|
10953
|
-
inflector.singularize('kine') //=> 'cow'
|
11873
|
+
inflector.pluralize('cow'); //=> 'kine'
|
11874
|
+
inflector.singularize('kine'); //=> 'cow'
|
10954
11875
|
```
|
10955
11876
|
|
10956
11877
|
Creating an inflector and adding rules later.
|
@@ -10958,13 +11879,13 @@ define("ember-inflector/lib/system/inflector",
|
|
10958
11879
|
```javascript
|
10959
11880
|
var inflector = Ember.Inflector.inflector;
|
10960
11881
|
|
10961
|
-
inflector.pluralize('advice') // => 'advices'
|
11882
|
+
inflector.pluralize('advice'); // => 'advices'
|
10962
11883
|
inflector.uncountable('advice');
|
10963
|
-
inflector.pluralize('advice') // => 'advice'
|
11884
|
+
inflector.pluralize('advice'); // => 'advice'
|
10964
11885
|
|
10965
|
-
inflector.pluralize('formula') // => 'formulas'
|
11886
|
+
inflector.pluralize('formula'); // => 'formulas'
|
10966
11887
|
inflector.irregular('formula', 'formulae');
|
10967
|
-
inflector.pluralize('formula') // => 'formulae'
|
11888
|
+
inflector.pluralize('formula'); // => 'formulae'
|
10968
11889
|
|
10969
11890
|
// you would not need to add these as they are the default rules
|
10970
11891
|
inflector.plural(/$/, 's');
|
@@ -11129,4 +12050,4 @@ define("ember-inflector/lib/system/string",
|
|
11129
12050
|
__exports__.singularize = singularize;
|
11130
12051
|
});
|
11131
12052
|
global.DS = requireModule('ember-data/lib/main')['default'];
|
11132
|
-
}(
|
12053
|
+
}(Ember.lookup));
|