ember-data-source 2.2.0.beta.3 → 2.2.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -261,6 +261,8 @@
261
261
  var ember$data$lib$adapters$errors$$EmberError = Ember.Error;
262
262
 
263
263
  var ember$data$lib$adapters$errors$$SOURCE_POINTER_REGEXP = /^\/?data\/(attributes|relationships)\/(.*)/;
264
+ var ember$data$lib$adapters$errors$$SOURCE_POINTER_PRIMARY_REGEXP = /^\/?data/;
265
+ var ember$data$lib$adapters$errors$$PRIMARY_ATTRIBUTE_KEY = 'base';
264
266
 
265
267
  /**
266
268
  @class AdapterError
@@ -318,11 +320,11 @@
318
320
  return Ember.RSVP.reject(new DS.InvalidError([
319
321
  {
320
322
  detail: 'Must be unique',
321
- source: { pointer: 'data/attributes/title' }
323
+ source: { pointer: '/data/attributes/title' }
322
324
  },
323
325
  {
324
326
  detail: 'Must not be blank',
325
- source: { pointer: 'data/attributes/content'}
327
+ source: { pointer: '/data/attributes/content'}
326
328
  }
327
329
  ]));
328
330
  }
@@ -380,11 +382,17 @@
380
382
  Object.keys(errors).forEach(function (key) {
381
383
  var messages = Ember.makeArray(errors[key]);
382
384
  for (var i = 0; i < messages.length; i++) {
385
+ var title = 'Invalid Attribute';
386
+ var pointer = '/data/attributes/' + key;
387
+ if (key === ember$data$lib$adapters$errors$$PRIMARY_ATTRIBUTE_KEY) {
388
+ title = 'Invalid Document';
389
+ pointer = '/data';
390
+ }
383
391
  out.push({
384
- title: 'Invalid Attribute',
392
+ title: title,
385
393
  detail: messages[i],
386
394
  source: {
387
- pointer: '/data/attributes/' + key
395
+ pointer: pointer
388
396
  }
389
397
  });
390
398
  }
@@ -409,6 +417,11 @@
409
417
 
410
418
  if (key) {
411
419
  key = key[2];
420
+ } else if (error.source.pointer.search(ember$data$lib$adapters$errors$$SOURCE_POINTER_PRIMARY_REGEXP) !== -1) {
421
+ key = ember$data$lib$adapters$errors$$PRIMARY_ATTRIBUTE_KEY;
422
+ }
423
+
424
+ if (key) {
412
425
  out[key] = out[key] || [];
413
426
  out[key].push(error.detail || error.title);
414
427
  }
@@ -1868,7 +1881,7 @@
1868
1881
  });
1869
1882
 
1870
1883
  var ember$data$lib$core$$DS = Ember.Namespace.create({
1871
- VERSION: '2.2.0-beta.3'
1884
+ VERSION: '2.2.0-beta.4'
1872
1885
  });
1873
1886
 
1874
1887
  if (Ember.libraries) {
@@ -2344,6 +2357,90 @@
2344
2357
  return record;
2345
2358
  }, null, "DS: Extract payload of queryRecord " + typeClass);
2346
2359
  }
2360
+
2361
+ var ember$data$lib$utils$$get = ember$lib$main$$default.get;
2362
+
2363
+ /**
2364
+ Assert that `addedRecord` has a valid type so it can be added to the
2365
+ relationship of the `record`.
2366
+
2367
+ The assert basically checks if the `addedRecord` can be added to the
2368
+ relationship (specified via `relationshipMeta`) of the `record`.
2369
+
2370
+ This utility should only be used internally, as both record parameters must
2371
+ be an InternalModel and the `relationshipMeta` needs to be the meta
2372
+ information about the relationship, retrieved via
2373
+ `record.relationshipFor(key)`.
2374
+
2375
+ @method assertPolymorphicType
2376
+ @param {InternalModel} record
2377
+ @param {RelationshipMeta} relationshipMeta retrieved via
2378
+ `record.relationshipFor(key)`
2379
+ @param {InternalModel} addedRecord record which
2380
+ should be added/set for the relationship
2381
+ */
2382
+ var ember$data$lib$utils$$assertPolymorphicType = function (record, relationshipMeta, addedRecord) {
2383
+ var addedType = addedRecord.type.modelName;
2384
+ var recordType = record.type.modelName;
2385
+ var key = relationshipMeta.key;
2386
+ var typeClass = record.store.modelFor(relationshipMeta.type);
2387
+
2388
+ var assertionMessage = 'You cannot add a record of type \'' + addedType + '\' to the \'' + recordType + '.' + key + '\' relationship (only \'' + typeClass.modelName + '\' allowed)';
2389
+
2390
+ ember$lib$main$$default.assert(assertionMessage, ember$data$lib$utils$$checkPolymorphic(typeClass, addedRecord));
2391
+ };
2392
+
2393
+ function ember$data$lib$utils$$checkPolymorphic(typeClass, addedRecord) {
2394
+ if (typeClass.__isMixin) {
2395
+ //TODO Need to do this in order to support mixins, should convert to public api
2396
+ //once it exists in Ember
2397
+ return typeClass.__mixin.detect(addedRecord.type.PrototypeMixin);
2398
+ }
2399
+ if (ember$lib$main$$default.MODEL_FACTORY_INJECTIONS) {
2400
+ typeClass = typeClass.superclass;
2401
+ }
2402
+ return typeClass.detect(addedRecord.type);
2403
+ }
2404
+
2405
+ /**
2406
+ Check if the passed model has a `type` attribute or a relationship named `type`.
2407
+
2408
+ @method modelHasAttributeOrRelationshipNamedType
2409
+ @param modelClass
2410
+ */
2411
+ function ember$data$lib$utils$$modelHasAttributeOrRelationshipNamedType(modelClass) {
2412
+ return ember$data$lib$utils$$get(modelClass, 'attributes').has('type') || ember$data$lib$utils$$get(modelClass, 'relationshipsByName').has('type');
2413
+ }
2414
+
2415
+ /*
2416
+ ember-container-inject-owner is a new feature in Ember 2.3 that finally provides a public
2417
+ API for looking items up. This function serves as a super simple polyfill to avoid
2418
+ triggering deprecations.
2419
+ */
2420
+ function ember$data$lib$utils$$getOwner(context) {
2421
+ var owner;
2422
+
2423
+ if (ember$lib$main$$default.getOwner) {
2424
+ owner = ember$lib$main$$default.getOwner(context);
2425
+ }
2426
+
2427
+ if (!owner && context.container) {
2428
+ owner = context.container;
2429
+ }
2430
+
2431
+ if (owner && owner.lookupFactory && !owner._lookupFactory) {
2432
+ // `owner` is a container, we are just making this work
2433
+ owner._lookupFactory = owner.lookupFactory;
2434
+ owner.register = function () {
2435
+ var registry = owner.registry || owner._registry || owner;
2436
+
2437
+ return registry.register.apply(registry, arguments);
2438
+ };
2439
+ }
2440
+
2441
+ return owner;
2442
+ }
2443
+
2347
2444
  var ember$data$lib$system$coerce$id$$default = ember$data$lib$system$coerce$id$$coerceId;
2348
2445
  // Used by the store to normalize IDs entering the store. Despite the fact
2349
2446
  // that developers may provide IDs as numbers (e.g., `store.find(Person, 1)`),
@@ -3079,8 +3176,8 @@
3079
3176
  * @class ContainerInstanceCache
3080
3177
  *
3081
3178
  */
3082
- function ember$data$lib$system$store$container$instance$cache$$ContainerInstanceCache(container) {
3083
- this._container = container;
3179
+ function ember$data$lib$system$store$container$instance$cache$$ContainerInstanceCache(owner) {
3180
+ this._owner = owner;
3084
3181
  this._cache = new ember$data$lib$system$empty$object$$default();
3085
3182
  }
3086
3183
 
@@ -3115,7 +3212,7 @@
3115
3212
  instanceFor: function (key) {
3116
3213
  var cache = this._cache;
3117
3214
  if (!cache[key]) {
3118
- var instance = this._container.lookup(key);
3215
+ var instance = this._owner.lookup(key);
3119
3216
  if (instance) {
3120
3217
  cache[key] = instance;
3121
3218
  }
@@ -3134,7 +3231,7 @@
3134
3231
  cacheEntry.destroy();
3135
3232
  }
3136
3233
  }
3137
- this._container = null;
3234
+ this._owner = null;
3138
3235
  },
3139
3236
 
3140
3237
  constructor: ember$data$lib$system$store$container$instance$cache$$ContainerInstanceCache,
@@ -3405,15 +3502,18 @@
3405
3502
  loadingData: Ember.K,
3406
3503
 
3407
3504
  propertyWasReset: function (internalModel, name) {
3408
- var length = Object.keys(internalModel._attributes).length;
3409
- var stillDirty = length > 0;
3410
-
3411
- if (!stillDirty) {
3505
+ if (!internalModel.hasChangedAttributes()) {
3412
3506
  internalModel.send('rolledBack');
3413
3507
  }
3414
3508
  },
3415
3509
 
3416
- pushedData: Ember.K,
3510
+ pushedData: function (internalModel) {
3511
+ internalModel.updateChangedAttributes();
3512
+
3513
+ if (!internalModel.hasChangedAttributes()) {
3514
+ internalModel.transitionTo('loaded.saved');
3515
+ }
3516
+ },
3417
3517
 
3418
3518
  becomeDirty: Ember.K,
3419
3519
 
@@ -3699,10 +3799,7 @@
3699
3799
  // in the `saved` state.
3700
3800
  saved: {
3701
3801
  setup: function (internalModel) {
3702
- var attrs = internalModel._attributes;
3703
- var isDirty = Object.keys(attrs).length > 0;
3704
-
3705
- if (isDirty) {
3802
+ if (internalModel.hasChangedAttributes()) {
3706
3803
  internalModel.adapterDidDirty();
3707
3804
  }
3708
3805
  },
@@ -4393,60 +4490,6 @@
4393
4490
  }
4394
4491
  });
4395
4492
 
4396
- var ember$data$lib$utils$$get = ember$lib$main$$default.get;
4397
-
4398
- /**
4399
- Assert that `addedRecord` has a valid type so it can be added to the
4400
- relationship of the `record`.
4401
-
4402
- The assert basically checks if the `addedRecord` can be added to the
4403
- relationship (specified via `relationshipMeta`) of the `record`.
4404
-
4405
- This utility should only be used internally, as both record parameters must
4406
- be an InternalModel and the `relationshipMeta` needs to be the meta
4407
- information about the relationship, retrieved via
4408
- `record.relationshipFor(key)`.
4409
-
4410
- @method assertPolymorphicType
4411
- @param {InternalModel} record
4412
- @param {RelationshipMeta} relationshipMeta retrieved via
4413
- `record.relationshipFor(key)`
4414
- @param {InternalModel} addedRecord record which
4415
- should be added/set for the relationship
4416
- */
4417
- var ember$data$lib$utils$$assertPolymorphicType = function (record, relationshipMeta, addedRecord) {
4418
- var addedType = addedRecord.type.modelName;
4419
- var recordType = record.type.modelName;
4420
- var key = relationshipMeta.key;
4421
- var typeClass = record.store.modelFor(relationshipMeta.type);
4422
-
4423
- var assertionMessage = 'You cannot add a record of type \'' + addedType + '\' to the \'' + recordType + '.' + key + '\' relationship (only \'' + typeClass.modelName + '\' allowed)';
4424
-
4425
- ember$lib$main$$default.assert(assertionMessage, ember$data$lib$utils$$checkPolymorphic(typeClass, addedRecord));
4426
- };
4427
-
4428
- function ember$data$lib$utils$$checkPolymorphic(typeClass, addedRecord) {
4429
- if (typeClass.__isMixin) {
4430
- //TODO Need to do this in order to support mixins, should convert to public api
4431
- //once it exists in Ember
4432
- return typeClass.__mixin.detect(addedRecord.type.PrototypeMixin);
4433
- }
4434
- if (ember$lib$main$$default.MODEL_FACTORY_INJECTIONS) {
4435
- typeClass = typeClass.superclass;
4436
- }
4437
- return typeClass.detect(addedRecord.type);
4438
- }
4439
-
4440
- /**
4441
- Check if the passed model has a `type` attribute or a relationship named `type`.
4442
-
4443
- @method modelHasAttributeOrRelationshipNamedType
4444
- @param modelClass
4445
- */
4446
- function ember$data$lib$utils$$modelHasAttributeOrRelationshipNamedType(modelClass) {
4447
- return ember$data$lib$utils$$get(modelClass, 'attributes').has('type') || ember$data$lib$utils$$get(modelClass, 'relationshipsByName').has('type');
4448
- }
4449
-
4450
4493
  var ember$data$lib$system$relationships$state$has$many$$default = ember$data$lib$system$relationships$state$has$many$$ManyRelationship;
4451
4494
  function ember$data$lib$system$relationships$state$has$many$$ManyRelationship(store, record, inverseKey, relationshipMeta) {
4452
4495
  this._super$constructor(store, record, inverseKey, relationshipMeta);
@@ -5161,6 +5204,7 @@
5161
5204
  var ember$data$lib$system$model$internal$model$$Promise = Ember.RSVP.Promise;
5162
5205
  var ember$data$lib$system$model$internal$model$$get = Ember.get;
5163
5206
  var ember$data$lib$system$model$internal$model$$set = Ember.set;
5207
+ var ember$data$lib$system$model$internal$model$$copy = Ember.copy;
5164
5208
 
5165
5209
  var ember$data$lib$system$model$internal$model$$_extractPivotNameCache = new ember$data$lib$system$empty$object$$default();
5166
5210
  var ember$data$lib$system$model$internal$model$$_splitOnDotCache = new ember$data$lib$system$empty$object$$default();
@@ -5195,11 +5239,10 @@
5195
5239
 
5196
5240
  @class InternalModel
5197
5241
  */
5198
- function ember$data$lib$system$model$internal$model$$InternalModel(type, id, store, container, data) {
5242
+ function ember$data$lib$system$model$internal$model$$InternalModel(type, id, store, _, data) {
5199
5243
  this.type = type;
5200
5244
  this.id = id;
5201
5245
  this.store = store;
5202
- this.container = container;
5203
5246
  this._data = data || new ember$data$lib$system$empty$object$$default();
5204
5247
  this.modelName = type.modelName;
5205
5248
  this.dataHasInitialized = false;
@@ -5253,17 +5296,27 @@
5253
5296
  constructor: ember$data$lib$system$model$internal$model$$InternalModel,
5254
5297
  materializeRecord: function () {
5255
5298
  Ember.assert("Materialized " + this.modelName + " record with id:" + this.id + "more than once", this.record === null || this.record === undefined);
5299
+
5256
5300
  // lookupFactory should really return an object that creates
5257
5301
  // instances with the injections applied
5258
- this.record = this.type._create({
5302
+ var createOptions = {
5259
5303
  store: this.store,
5260
- container: this.container,
5261
5304
  _internalModel: this,
5262
5305
  id: this.id,
5263
5306
  currentState: ember$data$lib$system$model$internal$model$$get(this, 'currentState'),
5264
5307
  isError: this.isError,
5265
5308
  adapterError: this.error
5266
- });
5309
+ };
5310
+
5311
+ if (Ember.setOwner) {
5312
+ // ensure that `Ember.getOwner(this)` works inside a model instance
5313
+ Ember.setOwner(createOptions, ember$data$lib$utils$$getOwner(this.store));
5314
+ } else {
5315
+ createOptions.container = this.store.container;
5316
+ }
5317
+
5318
+ this.record = this.type._create(createOptions);
5319
+
5267
5320
  this._triggerDeferredTriggers();
5268
5321
  },
5269
5322
 
@@ -5415,6 +5468,53 @@
5415
5468
  this._attributes = new ember$data$lib$system$empty$object$$default();
5416
5469
  },
5417
5470
 
5471
+ hasChangedAttributes: function () {
5472
+ return Object.keys(this._attributes).length > 0;
5473
+ },
5474
+
5475
+ /**
5476
+ Checks if the attributes which are considered as changed are still
5477
+ different to the state which is acknowledged by the server.
5478
+ This method is needed when data for the internal model is pushed and the
5479
+ pushed data might acknowledge dirty attributes as confirmed.
5480
+ */
5481
+ updateChangedAttributes: function () {
5482
+ var changedAttributes = this.changedAttributes();
5483
+ var changedAttributeNames = Object.keys(changedAttributes);
5484
+
5485
+ for (var i = 0, _length = changedAttributeNames.length; i < _length; i++) {
5486
+ var attribute = changedAttributeNames[i];
5487
+ var _changedAttributes$attribute = changedAttributes[attribute];
5488
+ var oldData = _changedAttributes$attribute[0];
5489
+ var newData = _changedAttributes$attribute[1];
5490
+
5491
+ if (oldData === newData) {
5492
+ delete this._attributes[attribute];
5493
+ }
5494
+ }
5495
+ },
5496
+
5497
+ /**
5498
+ Returns an object, whose keys are changed properties, and value is an
5499
+ [oldProp, newProp] array.
5500
+ */
5501
+ changedAttributes: function () {
5502
+ var oldData = this._data;
5503
+ var currentData = this._attributes;
5504
+ var inFlightData = this._inFlightAttributes;
5505
+ var newData = ember$data$lib$system$merge$$default(ember$data$lib$system$model$internal$model$$copy(inFlightData), currentData);
5506
+ var diffData = new ember$data$lib$system$empty$object$$default();
5507
+
5508
+ var newDataKeys = Object.keys(newData);
5509
+
5510
+ for (var i = 0, _length2 = newDataKeys.length; i < _length2; i++) {
5511
+ var key = newDataKeys[i];
5512
+ diffData[key] = [oldData[key], newData[key]];
5513
+ }
5514
+
5515
+ return diffData;
5516
+ },
5517
+
5418
5518
  /**
5419
5519
  @method adapterWillCommit
5420
5520
  @private
@@ -6065,7 +6165,7 @@
6065
6165
  store: this
6066
6166
  });
6067
6167
  this._pendingSave = [];
6068
- this._instanceCache = new ember$data$lib$system$store$container$instance$cache$$default(this.container);
6168
+ this._instanceCache = new ember$data$lib$system$store$container$instance$cache$$default(ember$data$lib$utils$$getOwner(this));
6069
6169
  //Used to keep track of all the find requests that need to be coalesced
6070
6170
  this._pendingFetch = ember$data$lib$system$store$$Map.create();
6071
6171
  },
@@ -7233,11 +7333,12 @@
7233
7333
  // container.registry = 2.1
7234
7334
  // container._registry = 1.11 - 2.0
7235
7335
  // container = < 1.11
7236
- var registry = this.container.registry || this.container._registry || this.container;
7237
- var mixin = this.container.lookupFactory('mixin:' + normalizedModelName);
7336
+ var owner = ember$data$lib$utils$$getOwner(this);
7337
+
7338
+ var mixin = owner._lookupFactory('mixin:' + normalizedModelName);
7238
7339
  if (mixin) {
7239
7340
  //Cache the class as a model
7240
- registry.register('model:' + normalizedModelName, DS.Model.extend(mixin));
7341
+ owner.register('model:' + normalizedModelName, DS.Model.extend(mixin));
7241
7342
  }
7242
7343
  var factory = this.modelFactoryFor(normalizedModelName);
7243
7344
  if (factory) {
@@ -7275,7 +7376,10 @@
7275
7376
  modelFactoryFor: function (modelName) {
7276
7377
  Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + Ember.inspect(modelName), typeof modelName === 'string');
7277
7378
  var normalizedKey = ember$data$lib$system$normalize$model$name$$default(modelName);
7278
- return this.container.lookupFactory('model:' + normalizedKey);
7379
+
7380
+ var owner = ember$data$lib$utils$$getOwner(this);
7381
+
7382
+ return owner._lookupFactory('model:' + normalizedKey);
7279
7383
  },
7280
7384
 
7281
7385
  /**
@@ -7431,7 +7535,7 @@
7431
7535
  },
7432
7536
 
7433
7537
  _hasModelFor: function (type) {
7434
- return this.container.lookupFactory("model:" + type);
7538
+ return ember$data$lib$utils$$getOwner(this)._lookupFactory("model:" + type);
7435
7539
  },
7436
7540
 
7437
7541
  _pushInternalModel: function (data) {
@@ -7582,7 +7686,7 @@
7582
7686
 
7583
7687
  // lookupFactory should really return an object that creates
7584
7688
  // instances with the injections applied
7585
- var internalModel = new ember$data$lib$system$model$internal$model$$default(type, id, this, this.container, data);
7689
+ var internalModel = new ember$data$lib$system$model$internal$model$$default(type, id, this, null, data);
7586
7690
 
7587
7691
  // if we're creating an item, this process will be done
7588
7692
  // later, once the object has been persisted.
@@ -8612,19 +8716,28 @@
8612
8716
  @method normalizeUsingDeclaredMapping
8613
8717
  @private
8614
8718
  */
8615
- normalizeUsingDeclaredMapping: function (typeClass, hash) {
8719
+ normalizeUsingDeclaredMapping: function (modelClass, hash) {
8616
8720
  var attrs = ember$data$lib$serializers$json$serializer$$get(this, 'attrs');
8617
- var payloadKey, key;
8721
+ var payloadKey, normalizedKey, key;
8618
8722
 
8619
8723
  if (attrs) {
8620
8724
  for (key in attrs) {
8621
- payloadKey = this._getMappedKey(key);
8725
+ payloadKey = this._getMappedKey(key, modelClass);
8726
+
8622
8727
  if (!hash.hasOwnProperty(payloadKey)) {
8623
8728
  continue;
8624
8729
  }
8625
8730
 
8626
- if (payloadKey !== key) {
8627
- hash[key] = hash[payloadKey];
8731
+ if (ember$data$lib$serializers$json$serializer$$get(modelClass, 'attributes').has(key)) {
8732
+ normalizedKey = this.keyForAttribute(key);
8733
+ }
8734
+
8735
+ if (ember$data$lib$serializers$json$serializer$$get(modelClass, 'relationshipsByName').has(key)) {
8736
+ normalizedKey = this.keyForRelationship(key);
8737
+ }
8738
+
8739
+ if (payloadKey !== normalizedKey) {
8740
+ hash[normalizedKey] = hash[payloadKey];
8628
8741
  delete hash[payloadKey];
8629
8742
  }
8630
8743
  }
@@ -8654,7 +8767,9 @@
8654
8767
  @param {String} key
8655
8768
  @return {String} key
8656
8769
  */
8657
- _getMappedKey: function (key) {
8770
+ _getMappedKey: function (key, modelClass) {
8771
+ Ember.assert('There is no attribute or relationship with the name `' + key + '` on `' + modelClass.modelName + '`. Check your serializers attrs hash.', ember$data$lib$serializers$json$serializer$$get(modelClass, 'attributes').has(key) || ember$data$lib$serializers$json$serializer$$get(modelClass, 'relationshipsByName').has(key));
8772
+
8658
8773
  var attrs = ember$data$lib$serializers$json$serializer$$get(this, 'attrs');
8659
8774
  var mappedKey;
8660
8775
  if (attrs && attrs[key]) {
@@ -8919,7 +9034,7 @@
8919
9034
 
8920
9035
  // if provided, use the mapping provided by `attrs` in
8921
9036
  // the serializer
8922
- var payloadKey = this._getMappedKey(key);
9037
+ var payloadKey = this._getMappedKey(key, snapshot.type);
8923
9038
 
8924
9039
  if (payloadKey === key && this.keyForAttribute) {
8925
9040
  payloadKey = this.keyForAttribute(key, 'serialize');
@@ -8957,7 +9072,7 @@
8957
9072
 
8958
9073
  // if provided, use the mapping provided by `attrs` in
8959
9074
  // the serializer
8960
- var payloadKey = this._getMappedKey(key);
9075
+ var payloadKey = this._getMappedKey(key, snapshot.type);
8961
9076
  if (payloadKey === key && this.keyForRelationship) {
8962
9077
  payloadKey = this.keyForRelationship(key, "belongsTo", "serialize");
8963
9078
  }
@@ -9005,7 +9120,7 @@
9005
9120
  if (hasMany !== undefined) {
9006
9121
  // if provided, use the mapping provided by `attrs` in
9007
9122
  // the serializer
9008
- var payloadKey = this._getMappedKey(key);
9123
+ var payloadKey = this._getMappedKey(key, snapshot.type);
9009
9124
  if (payloadKey === key && this.keyForRelationship) {
9010
9125
  payloadKey = this.keyForRelationship(key, "hasMany", "serialize");
9011
9126
  }
@@ -9192,8 +9307,10 @@
9192
9307
  @return {DS.Transform} transform
9193
9308
  */
9194
9309
  transformFor: function (attributeType, skipAssertion) {
9195
- var transform = this.container.lookup('transform:' + attributeType);
9310
+ var transform = ember$data$lib$utils$$getOwner(this).lookup('transform:' + attributeType);
9311
+
9196
9312
  Ember.assert("Unable to find transform for '" + attributeType + "'", skipAssertion || !!transform);
9313
+
9197
9314
  return transform;
9198
9315
  }
9199
9316
  });
@@ -9938,7 +10055,8 @@
9938
10055
  value = transform.serialize(value);
9939
10056
  }
9940
10057
 
9941
- var payloadKey = this._getMappedKey(key);
10058
+ var payloadKey = this._getMappedKey(key, snapshot.type);
10059
+
9942
10060
  if (payloadKey === key) {
9943
10061
  payloadKey = this.keyForAttribute(key, 'serialize');
9944
10062
  }
@@ -9962,7 +10080,7 @@
9962
10080
 
9963
10081
  json.relationships = json.relationships || {};
9964
10082
 
9965
- var payloadKey = this._getMappedKey(key);
10083
+ var payloadKey = this._getMappedKey(key, snapshot.type);
9966
10084
  if (payloadKey === key) {
9967
10085
  payloadKey = this.keyForRelationship(key, 'belongsTo', 'serialize');
9968
10086
  }
@@ -9997,7 +10115,7 @@
9997
10115
 
9998
10116
  json.relationships = json.relationships || {};
9999
10117
 
10000
- var payloadKey = this._getMappedKey(key);
10118
+ var payloadKey = this._getMappedKey(key, snapshot.type);
10001
10119
  if (payloadKey === key && this.keyForRelationship) {
10002
10120
  payloadKey = this.keyForRelationship(key, 'hasMany', 'serialize');
10003
10121
  }
@@ -11197,8 +11315,6 @@
11197
11315
  */
11198
11316
 
11199
11317
  var ember$data$lib$system$model$model$$get = Ember.get;
11200
- var ember$data$lib$system$model$model$$merge = Ember.merge;
11201
- var ember$data$lib$system$model$model$$copy = Ember.copy;
11202
11318
 
11203
11319
  function ember$data$lib$system$model$model$$intersection(array1, array2) {
11204
11320
  var result = [];
@@ -11723,20 +11839,7 @@
11723
11839
  and value is an [oldProp, newProp] array.
11724
11840
  */
11725
11841
  changedAttributes: function () {
11726
- var oldData = ember$data$lib$system$model$model$$get(this._internalModel, '_data');
11727
- var currentData = ember$data$lib$system$model$model$$get(this._internalModel, '_attributes');
11728
- var inFlightData = ember$data$lib$system$model$model$$get(this._internalModel, '_inFlightAttributes');
11729
- var newData = ember$data$lib$system$model$model$$merge(ember$data$lib$system$model$model$$copy(inFlightData), currentData);
11730
- var diffData = new ember$data$lib$system$empty$object$$default();
11731
-
11732
- var newDataKeys = Object.keys(newData);
11733
-
11734
- for (var i = 0, _length = newDataKeys.length; i < _length; i++) {
11735
- var key = newDataKeys[i];
11736
- diffData[key] = [oldData[key], newData[key]];
11737
- }
11738
-
11739
- return diffData;
11842
+ return this._internalModel.changedAttributes();
11740
11843
  },
11741
11844
 
11742
11845
  //TODO discuss with tomhuda about events/hooks
@@ -11947,6 +12050,23 @@
11947
12050
  modelName: null
11948
12051
  });
11949
12052
 
12053
+ // if `Ember.setOwner` is defined, accessing `this.container` is
12054
+ // deprecated (but functional). In "standard" Ember usage, this
12055
+ // deprecation is actually created via an `.extend` of the factory
12056
+ // inside the container itself, but that only happens on models
12057
+ // with MODEL_FACTORY_INJECTIONS enabled :(
12058
+ if (Ember.setOwner) {
12059
+ Object.defineProperty(ember$data$lib$system$model$model$$Model.prototype, 'container', {
12060
+ configurable: true,
12061
+ enumerable: false,
12062
+ get: function () {
12063
+ Ember.deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.', false, { id: 'ember-application.injected-container', until: '3.0.0' });
12064
+
12065
+ return this.store.container;
12066
+ }
12067
+ });
12068
+ }
12069
+
11950
12070
  var ember$data$lib$system$model$model$$default = ember$data$lib$system$model$model$$Model;
11951
12071
  var ember$data$lib$system$model$attributes$$default = ember$data$lib$system$model$attributes$$attr;
11952
12072
 
@@ -12784,6 +12904,10 @@
12784
12904
  json[key] = null;
12785
12905
  } else {
12786
12906
  json[key] = embeddedSnapshot.id;
12907
+
12908
+ if (relationship.options.polymorphic) {
12909
+ this.serializePolymorphicType(snapshot, json, relationship);
12910
+ }
12787
12911
  }
12788
12912
  } else if (includeRecords) {
12789
12913
  this._serializeEmbeddedBelongsTo(snapshot, json, relationship);
@@ -12798,6 +12922,10 @@
12798
12922
  } else {
12799
12923
  json[serializedKey] = embeddedSnapshot.record.serialize({ includeId: true });
12800
12924
  this.removeEmbeddedForeignKey(snapshot, embeddedSnapshot, relationship, json[serializedKey]);
12925
+
12926
+ if (relationship.options.polymorphic) {
12927
+ this.serializePolymorphicType(snapshot, json, relationship);
12928
+ }
12801
12929
  }
12802
12930
  },
12803
12931