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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c30d9bd2bffbba3064ced349b8b257a36ae7bdc3
4
- data.tar.gz: 870dc095c98df02b8721d66630a6fa3adfa64b2b
3
+ metadata.gz: dd4aa876cc306a2a0cbff22651c995e2e160c386
4
+ data.tar.gz: e121beba0aff64936804f83dfb014c736fb3842d
5
5
  SHA512:
6
- metadata.gz: ddb4fa73c9ac26136586734172f11fa46216a244e2722c18a9cb33718e2af16a37fa90492a7f1a5bc218a26b07b7d25729f9099345bb82005eb01424a38e106f
7
- data.tar.gz: 33b783baf1246054e597ec3b6f9f0f7d683436f3dcc4d7d9637ef965e91352d0d2d2a4945ddff1d019d69b4797d9d634e98241c7142b3aa0c082ffe3c5c4cbd7
6
+ metadata.gz: a48bfb3adeaa4d01171de31c46aac67fefdc51460aafa0d595ea19497e8341a2b5a31f54b8340f5a9357d399d49502b636a071905ab9d07924ca508c51c5474c
7
+ data.tar.gz: 5bbe514b57a289565a45e68b5a1d851f6fde71bf48b9c83645ba8c987eaca8c7fd21b33bc67d4bcb08266fb2806fc6c7fe1e4460db7ed7b900352b117326442c
@@ -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.7+canary.f482da04
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","./initializers","exports"],
90
- function(__dependency1__, __dependency2__, __exports__) {
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 camelcasing.
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.Adapter
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
- @returns String
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
- @returns error
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 camelcased attributes to underscored when serializing.
305
+ Converts camelCased attributes to underscored when serializing.
263
306
 
264
307
  @method keyForAttribute
265
308
  @param {String} attribute
266
- @returns String
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
- @returns String
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
- key = this.keyForAttribute(key);
323
- json[key + "_type"] = capitalize(camelize(belongsTo.constructor.typeKey));
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
- Extracts the model typeKey from underscored root objects.
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 this
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
- @returns Object
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} hash
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
- The EmbeddedRecordsMixin allows you to add embedded record support to your
468
- serializers.
469
- To set up embedded records, you include the mixin into the serializer and then
470
- define your embedded relations.
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
- comments: {embedded: 'always'}
514
+ author: {embedded: 'always'},
515
+ comments: {serialize: 'ids'}
476
516
  }
477
517
  })
478
518
  ```
479
519
 
480
- Currently only `{embedded: 'always'}` records are supported.
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 has-may relationship when it is configured as embedded objects.
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 key = relationship.key,
494
- attrs = get(this, 'attrs'),
495
- embed = attrs && attrs[key] && attrs[key].embedded === 'always';
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
- if (embed) {
498
- json[this.keyForAttribute(key)] = get(record, key).map(function(relation) {
499
- var data = relation.serialize(),
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
- data[primaryKey] = get(relation, primaryKey);
765
+ Serializing a `belongsTo` relationship removes the property that refers to the
766
+ parent record
503
767
 
504
- return data;
505
- }, this);
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 objects out of the payload for a single object
511
- and add them as sideloaded objects instead.
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, requestType) {
842
+ extractSingle: function(store, primaryType, payload, recordId) {
516
843
  var root = this.keyForAttribute(primaryType.typeKey),
517
844
  partial = payload[root];
518
845
 
519
- updatePayloadWithEmbedded(store, this, primaryType, partial, payload);
846
+ updatePayloadWithEmbedded(this, store, primaryType, payload, partial);
520
847
 
521
- return this._super(store, primaryType, payload, recordId, requestType);
848
+ return this._super(store, primaryType, payload, recordId);
522
849
  },
523
850
 
524
851
  /**
525
- Extract embedded objects out of a standard payload
526
- and add them as sideloaded objects instead.
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, type, payload) {
531
- var root = this.keyForAttribute(type.typeKey),
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, this, type, partial, payload);
906
+ updatePayloadWithEmbedded(this, store, primaryType, payload, partial);
536
907
  }, this);
537
908
 
538
- return this._super(store, type, payload);
909
+ return this._super(store, primaryType, payload);
539
910
  }
540
911
  });
541
912
 
542
- function updatePayloadWithEmbedded(store, serializer, type, partial, payload) {
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
- var expandedKey, embeddedTypeKey, attribute, ids,
551
- config = attrs[key],
552
- serializer = store.serializerFor(relationship.type.typeKey),
553
- primaryKey = get(serializer, "primaryKey");
554
-
555
- if (relationship.kind !== "hasMany") {
556
- return;
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
- if (config && (config.embedded === 'always' || config.embedded === 'load')) {
560
- // underscore forces the embedded records to be side loaded.
561
- // it is needed when main type === relationship.type
562
- embeddedTypeKey = '_' + Ember.String.pluralize(relationship.type.typeKey);
563
- expandedKey = this.keyForRelationship(key, relationship.kind);
564
- attribute = this.keyForAttribute(key);
565
- ids = [];
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
- if (!partial[attribute]) {
568
- return;
569
- }
990
+ payload[embeddedTypeKey] = payload[embeddedTypeKey] || [];
570
991
 
571
- payload[embeddedTypeKey] = payload[embeddedTypeKey] || [];
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
- forEach(partial[attribute], function(data) {
574
- var embeddedType = store.modelFor(relationship.type.typeKey);
575
- updatePayloadWithEmbedded(store, serializer, embeddedType, data, payload);
576
- ids.push(data[primaryKey]);
577
- payload[embeddedTypeKey].push(data);
578
- });
999
+ partial[expandedKey] = ids;
1000
+ delete partial[attribute];
1001
+ }
579
1002
 
580
- partial[expandedKey] = ids;
581
- delete partial[attribute];
582
- }
583
- }, serializer);
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
- Its primarily used for development and testing. You can also use
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. Its possible to do develop your entire application
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. An array of
1043
- headers can be added to the adapter which are passed with every request:
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.reopen({
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 key. An array of
1094
- headers can be added to the adapter which are passed with every request:
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.reopen({
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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
- @returns {String} url
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.reopen({
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
- @returns {String} path
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
- if (this.headers !== undefined) {
1555
- var headers = this.headers;
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.7+canary.f482da04'
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.7+canary.f482da04'
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
- ["./system/store","./serializers","./adapters","./system/debug/debug_adapter","./system/container_proxy","./transforms"],
1675
- function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__) {
2239
+ define("ember-data/lib/initializers/data_adapter",
2240
+ ["../system/debug/debug_adapter","exports"],
2241
+ function(__dependency1__, __exports__) {
1676
2242
  "use strict";
1677
- var Store = __dependency1__["default"];
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
- @module ember-data
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
- When the application is initialized, `App.Store` will automatically be
1715
- instantiated, and the instance of `App.PostsController` will have its `store`
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
- Ember.onLoad('Ember.Application', function(Application) {
1725
- Application.initializer({
1726
- name: "store",
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
- // new go forward paths
1741
- application.register('serializer:-default', JSONSerializer);
1742
- application.register('serializer:-rest', RESTSerializer);
1743
- application.register('adapter:-rest', RESTAdapter);
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
- // Eagerly generate the store so defaultStore is populated.
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
- Application.initializer({
1752
- name: "transforms",
1753
- before: "store",
2280
+ // allow older names to be looked up
1754
2281
 
1755
- initialize: function(container, application) {
1756
- application.register('transform:boolean', BooleanTransform);
1757
- application.register('transform:date', DateTransform);
1758
- application.register('transform:number', NumberTransform);
1759
- application.register('transform:string', StringTransform);
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
- Application.initializer({
1764
- name: "data-adapter",
1765
- before: "store",
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
- initialize: function(container, application) {
1768
- application.register('data-adapter:main', DebugAdapter);
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
- Application.initializer({
1773
- name: "injectStore",
1774
- before: "store",
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
- initialize: function(container, application) {
1777
- application.inject('controller', 'store', 'store:main');
1778
- application.inject('route', 'store', 'store:main');
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","./initializers","./system/container_proxy","exports"],
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 = __dependency18__["default"];
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 get = Ember.get, set = Ember.set, isNone = Ember.isNone;
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 you attributes were always
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 = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship);
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[key] = get(record, key).mapBy('id');
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, payload) {
2561
- return this.normalize(type, payload);
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
- @returns {Object}
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
- return this._super(type, hash, prop);
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(type, payload) {
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 {subclass of DS.Model} type
2856
- @param {Object} hash
2857
- @returns {Object} the normalized payload
3487
+ @param {Object} payload
3488
+ @return {Object} the normalized payload
2858
3489
  */
2859
- normalizePayload: function(type, payload) {
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, requestType) {
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, requestType);
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} type
3601
+ @param {subclass of DS.Model} primaryType
3005
3602
  @param {Object} payload
3006
- @param {String} id
3007
- @param {'find'|'createRecord'|'updateRecord'|'deleteRecord'} requestType
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, requestType) {
3011
- payload = this.normalizePayload(primaryType, payload);
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, id, requestType) {
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, id, requestType);
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} type
3745
+ @param {subclass of DS.Model} primaryType
3151
3746
  @param {Object} payload
3152
- @param {'findAll'|'findMany'|'findHasMany'|'findQuery'} requestType
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(primaryType, payload);
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(null, payload);
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 this.normalize(type, hash, prop);
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
- You can use this method to normalize the JSON root keys returned
3240
- into the model type expected by your store.
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
- For example, your server may return underscored root keys rather than
3243
- the expected camelcased versions.
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
- var camelized = Ember.String.camelize(root);
3249
- return Ember.String.singularize(camelized);
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} root
3256
- @returns {String} the model's typeKey
3873
+ @param {String} key
3874
+ @return {String} the model's typeKey
3257
3875
  */
3258
- typeForRoot: function(root) {
3259
- return Ember.String.singularize(root);
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 camelized root keys.
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
- var root = Ember.String.camelize(type.typeKey);
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"] = Ember.String.camelize(belongsTo.constructor.typeKey);
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
- First, create a new subclass of `DS.Adapter`:
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
- App.MyAdapter = DS.Adapter.extend({
4173
+ var MyAdapter = DS.Adapter.extend({
3532
4174
  // ...your code here
3533
4175
  });
4176
+
4177
+ App.ApplicationAdapter = MyAdapter;
3534
4178
  ```
3535
4179
 
3536
- To tell your store which adapter to use, set its `adapter` property:
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
- App.store = DS.Store.create({
3540
- adapter: 'MyAdapter'
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/attribute_change","./changes/relationship_change","exports"],
3907
- function(__dependency1__, __dependency2__, __exports__) {
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 AttributeChange = __dependency1__["default"];
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
- @returns {Array}
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).map(function(message) {
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
- @returns {Boolean} true if there some errors on given attribute
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(App.Model);
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(App.Model);
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.set('isDirty'); // true
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(App.Model);
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(App.Model);
5372
- record.get('isDeleted'); // false
6102
+ var record = store.createRecord('model');
6103
+ record.get('isDeleted'); // false
5373
6104
  record.deleteRecord();
5374
- record.get('isDeleted'); // true
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(App.Model);
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. A
5406
- record will be in the `valid` state when no client-side
5407
- validations have failed and the adapter did not report any
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(App.Model);
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. This may also result in the record having
5440
- its `isValid` property become false if the adapter reported that
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', 'invalid value');
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(App.Model);
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 {Object}
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
- @returns {Object} an object whose values are primitive JSON values only
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
- @returns {Object} A JSON representation of the object.
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 = DS.JSONSerializer.create({ container: this.container });
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 DS.PromiseObject.create({ promise: resolver.promise });
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 DS.PromiseObject.create({ promise: promise });
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: No client-side validations have failed and the
6509
- // adapter did not report any server-side validation failures.
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` state when its client-side
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 = DS.RecordArray.create({
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 = DS.FilteredRecordArray.create({
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 = DS.AdapterPopulatedRecordArray.create({
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)).forEach(destroy);
7274
- this._adapterPopulatedRecordArrays.forEach(destroy);
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
- updateFilter: Ember.observer(function() {
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, resolver);
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(App.Person);
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(App.Person);
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(App.Person);
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(App.Message);
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.modelFor(type));
7915
- return value === undefined ? null : DS.PromiseObject.create({
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 DS.PromiseObject.create({
8738
+ return PromiseObject.create({
7926
8739
  promise: promise
7927
8740
  });
7928
8741
  } else if (link) {
7929
- promise = store.findBelongsTo(this, link, meta);
7930
- return DS.PromiseObject.create({
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 or string, like DS.belongsTo(App.Person)", !!type && (typeof type === 'string' || DS.Model.detect(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 = DS.RelationshipChange.createChange(record, oldParent, store, { key: key, kind: "belongsTo", changeType: "remove" });
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 = DS.RelationshipChange.createChange(record, newParent, store, { key: key, kind: "belongsTo", changeType: "add" });
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 Model = __dependency2__.Model;
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
- if (typeof meta.type === 'string') {
8292
- meta.type = this.store.modelFor(meta.type);
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
- type = meta.type;
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(), type;
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
- type = meta.type;
8438
-
8439
- if (!type && meta.kind === 'hasMany') {
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.type, resolver);
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 DS.PromiseArray.create({
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.type);
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(App.Person, 123);
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 = DS.RecordArrayManager.create({
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
- @returns DS.Adapter
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 DS.Adapter));
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
- @returns {DS.Model} record
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
- @returns {String} if the adapter can generate one, an ID
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(App.Person, { page: 1 });
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
- @returns {Promise} promise
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
- @returns {Promise} promise
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) { return; }
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
- @returns {Boolean}
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
- @returns {DS.Model} record
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
- @returns {Promise} promise
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 local_posts = store.all(App.Post);
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(App.Post);
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(App.Post, {unread: true}, function(post) {
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 (arguments.length === 3) {
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
- var array = this.recordArrayManager
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(App.Post, 1); // false
9566
- store.find(App.Post, 1).then(function() {
9567
- store.recordIsLoaded(App.Post, 1); // true
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, 'isNew')) {
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
- @returns {subclass of DS.Model}
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
- @returns {DS.Model} the record that was created or
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('post', pushData);
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
- @returns {DS.Model} record
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
- @returns DS.Adapter
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 map = this.typeMaps;
10145
- var keys = Ember.keys(map);
11048
+ var typeMaps = this.typeMaps;
11049
+ var keys = Ember.keys(typeMaps);
10146
11050
  var store = this;
10147
- var types = keys.map(byType);
11051
+
11052
+ var types = map(keys, byType);
10148
11053
 
10149
11054
  this.recordArrayManager.destroy();
10150
11055
 
10151
- types.forEach(this.unloadAll, this);
11056
+ forEach(types, this.unloadAll, this);
10152
11057
 
10153
11058
  function byType(entry) {
10154
- return map[entry].type;
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 (isNone(id) || id instanceof DS.Model) {
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 the resulting value
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 DS.InvalidError) {
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
- App.RawTransform = DS.Transform.extend({
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 inflections = __dependency1__.inflections;
11712
+ var defaultRules = __dependency1__.defaultRules;
10792
11713
  var pluralize = __dependency1__.pluralize;
10793
11714
  var singularize = __dependency1__.singularize;
10794
11715
 
10795
- Inflector.defaultRules = inflections;
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
- }(window));
12053
+ }(Ember.lookup));