dist/globals/ember-data.prod.js in ember-data-source-3.0.2 vs dist/globals/ember-data.prod.js in ember-data-source-3.1.0.beta.1
- old
+ new
@@ -4,11 +4,11 @@
/*!
* @overview Ember Data
* @copyright Copyright 2011-2017 Tilde Inc. and contributors.
* Portions Copyright 2011 LivingSocial Inc.
* @license Licensed under MIT license (see license.js)
- * @version 3.0.2
+ * @version 3.1.0-beta.1
*/
var loader, define, requireModule, require, requirejs;
(function (global) {
@@ -1795,11 +1795,11 @@
Retrieves the `InternalModelMap` for a given modelName,
creating one if one did not already exist. This is
similar to `getWithDefault` or `get` on a `MapWithDefault`
@method retrieve
@param modelName a previously normalized modelName
- @returns {InternalModelMap} the InternalModelMap for the given modelName
+ @return {InternalModelMap} the InternalModelMap for the given modelName
*/
IdentityMap.prototype.retrieve = function retrieve(modelName) {
var map = this._map[modelName];
@@ -1862,13 +1862,13 @@
this._models = [];
this._metadata = null;
}
/**
- *
- * @param id
- * @returns {InternalModel}
+ * @method get
+ * @param id {String}
+ * @return {InternalModel}
*/
InternalModelMap.prototype.get = function get(id) {
return this._idToModel[id];
@@ -4746,14 +4746,10 @@
// If it is, get the metadata for the relationship. This is
// populated by the `DS.belongsTo` helper when it is creating
// the computed property.
var meta = value.meta();
- /*
- This is buggy because if the parent has never been looked up
- via `modelFor` it will not have `modelName` set.
- */
meta.parentType = proto.constructor;
}
}
});
}
@@ -7443,11 +7439,11 @@
userRef.value() === user;
});
```
@method push
- @param {Promise|Object}
+ @param objectOrPromise {Promise|Object}
@return Promise<record> a promise for the value (record or relationship)
*/
RecordReference.prototype.push = function (objectOrPromise) {
var _this = this;
@@ -7556,19 +7552,25 @@
}
return modelName;
}
function relationshipFromMeta(meta) {
- return {
+ var result = {
key: meta.key,
kind: meta.kind,
type: typeForRelationshipMeta(meta),
options: meta.options,
name: meta.name,
parentType: meta.parentType,
isRelationship: true
};
+
+ if (false) {
+ result.parentType = meta.parentType;
+ }
+
+ return result;
}
});
define('ember-data/-private/system/relationships/belongs-to', ['exports', 'ember-data/-private/system/normalize-model-name'], function (exports, _normalizeModelName) {
'use strict';
@@ -7966,18 +7968,17 @@
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
- var get = Ember.get;
+ var _get = Ember.get;
var RelationshipPayloadsManager = function () {
function RelationshipPayloadsManager(store) {
this._store = store;
// cache of `RelationshipPayload`s
this._cache = Object.create(null);
- this._inverseLookupCache = new _relationshipPayloads.TypeCache();
}
/**
Find the payload for the given relationship of the given model.
Returns the payload for the given relationship, whether raw or computed from
@@ -7994,194 +7995,90 @@
@method
*/
RelationshipPayloadsManager.prototype.get = function get(modelName, id, relationshipName) {
- var relationshipPayloads = this._getRelationshipPayloads(modelName, relationshipName, false);
+ var modelClass = this._store._modelFor(modelName);
+ var relationshipsByName = _get(modelClass, 'relationshipsByName');
+ var relationshipPayloads = this._getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, false);
return relationshipPayloads && relationshipPayloads.get(modelName, id, relationshipName);
};
RelationshipPayloadsManager.prototype.push = function push(modelName, id, relationshipsData) {
var _this = this;
if (!relationshipsData) {
return;
}
+ var modelClass = this._store._modelFor(modelName);
+ var relationshipsByName = _get(modelClass, 'relationshipsByName');
Object.keys(relationshipsData).forEach(function (key) {
- var relationshipPayloads = _this._getRelationshipPayloads(modelName, key, true);
+ var relationshipPayloads = _this._getRelationshipPayloads(modelName, key, modelClass, relationshipsByName, true);
if (relationshipPayloads) {
relationshipPayloads.push(modelName, id, key, relationshipsData[key]);
}
});
};
RelationshipPayloadsManager.prototype.unload = function unload(modelName, id) {
var _this2 = this;
var modelClass = this._store._modelFor(modelName);
- var relationshipsByName = get(modelClass, 'relationshipsByName');
+ var relationshipsByName = _get(modelClass, 'relationshipsByName');
relationshipsByName.forEach(function (_, relationshipName) {
- var relationshipPayloads = _this2._getRelationshipPayloads(modelName, relationshipName, false);
+ var relationshipPayloads = _this2._getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, false);
if (relationshipPayloads) {
relationshipPayloads.unload(modelName, id, relationshipName);
}
});
};
- RelationshipPayloadsManager.prototype._getRelationshipPayloads = function _getRelationshipPayloads(modelName, relationshipName, init) {
- var relInfo = this.getRelationshipInfo(modelName, relationshipName);
-
- if (relInfo === null) {
+ RelationshipPayloadsManager.prototype._getRelationshipPayloads = function _getRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName, init) {
+ if (!relationshipsByName.has(relationshipName)) {
return;
}
- var cache = this._cache[relInfo.lhs_key];
-
- if (!cache && init) {
- return this._initializeRelationshipPayloads(relInfo);
+ var key = modelName + ':' + relationshipName;
+ if (!this._cache[key] && init) {
+ return this._initializeRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName);
}
- return cache;
+ return this._cache[key];
};
- RelationshipPayloadsManager.prototype.getRelationshipInfo = function getRelationshipInfo(modelName, relationshipName) {
- var inverseCache = this._inverseLookupCache;
- var store = this._store;
- var cached = inverseCache.get(modelName, relationshipName);
-
- // CASE: We have a cached resolution (null if no relationship exists)
- if (cached !== undefined) {
- return cached;
- }
-
- var modelClass = store._modelFor(modelName);
- var relationshipsByName = get(modelClass, 'relationshipsByName');
-
- // CASE: We don't have a relationship at all
- if (!relationshipsByName.has(relationshipName)) {
- inverseCache.set(modelName, relationshipName, null);
- return null;
- }
-
- var inverseMeta = modelClass.inverseFor(relationshipName, store);
+ RelationshipPayloadsManager.prototype._initializeRelationshipPayloads = function _initializeRelationshipPayloads(modelName, relationshipName, modelClass, relationshipsByName) {
var relationshipMeta = relationshipsByName.get(relationshipName);
- var selfIsPolymorphic = relationshipMeta.options !== undefined && relationshipMeta.options.polymorphic === true;
- var inverseBaseModelName = relationshipMeta.type;
+ var inverseMeta = modelClass.inverseFor(relationshipName, this._store);
- // CASE: We have no inverse
- if (!inverseMeta) {
- var _info = {
- lhs_key: modelName + ':' + relationshipName,
- lhs_modelNames: [modelName],
- lhs_baseModelName: modelName,
- lhs_relationshipName: relationshipName,
- lhs_relationshipMeta: relationshipMeta,
- lhs_isPolymorphic: selfIsPolymorphic,
- rhs_key: '',
- rhs_modelNames: [],
- rhs_baseModelName: inverseBaseModelName,
- rhs_relationshipName: '',
- rhs_relationshipMeta: null,
- rhs_isPolymorphic: false,
- hasInverse: false,
- isSelfReferential: false, // modelName === inverseBaseModelName,
- isReflexive: false
- };
+ var inverseModelName = void 0;
+ var inverseRelationshipName = void 0;
+ var inverseRelationshipMeta = void 0;
- inverseCache.set(modelName, relationshipName, _info);
-
- return _info;
+ // figure out the inverse relationship; we need two things
+ // a) the inverse model name
+ //- b) the name of the inverse relationship
+ if (inverseMeta) {
+ inverseRelationshipName = inverseMeta.name;
+ inverseModelName = relationshipMeta.type;
+ inverseRelationshipMeta = _get(inverseMeta.type, 'relationshipsByName').get(inverseRelationshipName);
+ } else {
+ // relationship has no inverse
+ inverseModelName = inverseRelationshipName = '';
+ inverseRelationshipMeta = null;
}
- // CASE: We do have an inverse
+ var lhsKey = modelName + ':' + relationshipName;
+ var rhsKey = inverseModelName + ':' + inverseRelationshipName;
- var inverseRelationshipName = inverseMeta.name;
- var inverseRelationshipMeta = get(inverseMeta.type, 'relationshipsByName').get(inverseRelationshipName);
- var baseModelName = inverseRelationshipMeta.type;
- var isSelfReferential = baseModelName === inverseBaseModelName;
-
- // TODO we want to assert this but this breaks all of our shoddily written tests
- /*
- if (DEBUG) {
- let inverseDoubleCheck = inverseMeta.type.inverseFor(inverseRelationshipName, store);
- assert(`The ${inverseBaseModelName}:${inverseRelationshipName} relationship declares 'inverse: null', but it was resolved as the inverse for ${baseModelName}:${relationshipName}.`, inverseDoubleCheck);
- }
- */
-
- // CASE: We may have already discovered the inverse for the baseModelName
- // CASE: We have already discovered the inverse
- cached = inverseCache.get(baseModelName, relationshipName) || inverseCache.get(inverseBaseModelName, inverseRelationshipName);
- if (cached) {
- (false && Ember.assert('The ' + inverseBaseModelName + ':' + inverseRelationshipName + ' relationship declares \'inverse: null\', but it was resolved as the inverse for ' + baseModelName + ':' + relationshipName + '.', cached.hasInverse !== false));
-
-
- var isLHS = cached.lhs_baseModelName === baseModelName;
- var modelNames = isLHS ? cached.lhs_modelNames : cached.rhs_modelNames;
- // make this lookup easier in the future by caching the key
- modelNames.push(modelName);
- inverseCache.set(modelName, relationshipName, cached);
-
- return cached;
- }
-
- var info = {
- lhs_key: baseModelName + ':' + relationshipName,
- lhs_modelNames: [modelName],
- lhs_baseModelName: baseModelName,
- lhs_relationshipName: relationshipName,
- lhs_relationshipMeta: relationshipMeta,
- lhs_isPolymorphic: selfIsPolymorphic,
- rhs_key: inverseBaseModelName + ':' + inverseRelationshipName,
- rhs_modelNames: [],
- rhs_baseModelName: inverseBaseModelName,
- rhs_relationshipName: inverseRelationshipName,
- rhs_relationshipMeta: inverseRelationshipMeta,
- rhs_isPolymorphic: inverseRelationshipMeta.options !== undefined && inverseRelationshipMeta.options.polymorphic === true,
- hasInverse: true,
- isSelfReferential: isSelfReferential,
- isReflexive: isSelfReferential && relationshipName === inverseRelationshipName
- };
-
- // Create entries for the baseModelName as well as modelName to speed up
- // inverse lookups
- inverseCache.set(baseModelName, relationshipName, info);
- inverseCache.set(modelName, relationshipName, info);
-
- // Greedily populate the inverse
- inverseCache.set(inverseBaseModelName, inverseRelationshipName, info);
-
- return info;
- };
-
- RelationshipPayloadsManager.prototype._initializeRelationshipPayloads = function _initializeRelationshipPayloads(relInfo) {
- var lhsKey = relInfo.lhs_key;
- var rhsKey = relInfo.rhs_key;
- var existingPayloads = this._cache[lhsKey];
-
- if (relInfo.hasInverse === true && relInfo.rhs_isPolymorphic === true) {
- existingPayloads = this._cache[rhsKey];
-
- if (existingPayloads !== undefined) {
- this._cache[lhsKey] = existingPayloads;
- return existingPayloads;
- }
- }
-
// populate the cache for both sides of the relationship, as they both use
// the same `RelationshipPayloads`.
//
// This works out better than creating a single common key, because to
// compute that key we would need to do work to look up the inverse
//
- var cache = this._cache[lhsKey] = new _relationshipPayloads.default(relInfo);
-
- if (relInfo.hasInverse === true) {
- this._cache[rhsKey] = cache;
- }
-
- return cache;
+ return this._cache[lhsKey] = this._cache[rhsKey] = new _relationshipPayloads.default(this._store, modelName, relationshipName, relationshipMeta, inverseModelName, inverseRelationshipName, inverseRelationshipMeta);
};
return RelationshipPayloadsManager;
}();
@@ -8190,10 +8087,16 @@
define('ember-data/-private/system/relationships/relationship-payloads', ['exports'], function (exports) {
'use strict';
exports.__esModule = true;
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+
var _createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
@@ -8208,87 +8111,65 @@
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
- function _classCallCheck(instance, Constructor) {
- if (!(instance instanceof Constructor)) {
- throw new TypeError("Cannot call a class as a function");
- }
- }
+ var RelationshipPayloads = function () {
+ function RelationshipPayloads(store, modelName, relationshipName, relationshipMeta, inverseModelName, inverseRelationshipName, inverseRelationshipMeta) {
+ this._store = store;
- var TypeCache = exports.TypeCache = function () {
- function TypeCache() {
- this.types = Object.create(null);
- }
+ this._lhsModelName = modelName;
+ this._lhsRelationshipName = relationshipName;
+ this._lhsRelationshipMeta = relationshipMeta;
- TypeCache.prototype.get = function get(modelName, id) {
- var types = this.types;
+ this._rhsModelName = inverseModelName;
+ this._rhsRelationshipName = inverseRelationshipName;
+ this._rhsRelationshipMeta = inverseRelationshipMeta;
-
- if (types[modelName] !== undefined) {
- return types[modelName][id];
+ // a map of id -> payloads for the left hand side of the relationship.
+ this._lhsPayloads = Object.create(null);
+ if (modelName !== inverseModelName || relationshipName !== inverseRelationshipName) {
+ // The common case of a non-reflexive relationship, or a reflexive
+ // relationship whose inverse is not itself
+ this._rhsPayloads = Object.create(null);
+ this._isReflexive = false;
+ } else {
+ // Edge case when we have a reflexive relationship to itself
+ // eg user hasMany friends inverse friends
+ //
+ // In this case there aren't really two sides to the relationship, but
+ // we set `_rhsPayloads = _lhsPayloads` to make things easier to reason
+ // about
+ this._rhsPayloads = this._lhsPayloads;
+ this._isReflexive = true;
}
- };
- TypeCache.prototype.set = function set(modelName, id, payload) {
- var types = this.types;
-
- var typeMap = types[modelName];
-
- if (typeMap === undefined) {
- typeMap = types[modelName] = Object.create(null);
- }
-
- typeMap[id] = payload;
- };
-
- TypeCache.prototype.delete = function _delete(modelName, id) {
- var types = this.types;
-
-
- if (types[modelName] !== undefined) {
- delete types[modelName][id];
- }
- };
-
- return TypeCache;
- }();
-
- var RelationshipPayloads = function () {
- function RelationshipPayloads(relInfo) {
- this._relInfo = relInfo;
-
- // a map of id -> payloads for the left hand side of the relationship.
- this.lhs_payloads = new TypeCache();
- this.rhs_payloads = relInfo.isReflexive ? this.lhs_payloads : new TypeCache();
-
// When we push relationship payloads, just stash them in a queue until
// somebody actually asks for one of them.
//
// This is a queue of the relationship payloads that have been pushed for
// either side of this relationship
this._pendingPayloads = [];
}
/**
- Get the payload for the relationship of an individual record.
- This might return the raw payload as pushed into the store, or one computed
- from the payload of the inverse relationship.
- @method
- */
+ Get the payload for the relationship of an individual record.
+ This might return the raw payload as pushed into the store, or one computed
+ from the payload of the inverse relationship.
+ @method
+ */
RelationshipPayloads.prototype.get = function get(modelName, id, relationshipName) {
this._flushPending();
if (this._isLHS(modelName, relationshipName)) {
- return this.lhs_payloads.get(modelName, id);
+ return this._lhsPayloads[id];
} else {
- (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_key + '<->' + this._relInfo.rhs_key, this._isRHS(modelName, relationshipName)));
+ (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName)));
- return this.rhs_payloads.get(modelName, id);
+ return this._rhsPayloads[id];
}
};
RelationshipPayloads.prototype.push = function push(modelName, id, relationshipName, relationshipData) {
this._pendingPayloads.push([modelName, id, relationshipName, relationshipData]);
@@ -8296,44 +8177,24 @@
RelationshipPayloads.prototype.unload = function unload(modelName, id, relationshipName) {
this._flushPending();
if (this._isLHS(modelName, relationshipName)) {
- delete this.lhs_payloads.delete(modelName, id);
+ delete this._lhsPayloads[id];
} else {
- (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_baseModelName + ':' + this._relInfo.lhs_relationshipName + '<->' + this._relInfo.rhs_baseModelName + ':' + this._relInfo.rhs_relationshipName, this._isRHS(modelName, relationshipName)));
+ (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName)));
- delete this.rhs_payloads.delete(modelName, id);
+ delete this._rhsPayloads[id];
}
};
RelationshipPayloads.prototype._isLHS = function _isLHS(modelName, relationshipName) {
- var relInfo = this._relInfo;
- var isSelfReferential = relInfo.isSelfReferential;
- var isRelationship = relationshipName === relInfo.lhs_relationshipName;
-
- if (isRelationship === true) {
- return isSelfReferential === true || // itself
- modelName === relInfo.lhs_baseModelName || // base or non-polymorphic
- relInfo.lhs_modelNames.indexOf(modelName) !== -1; // polymorphic
- }
-
- return false;
+ return modelName === this._lhsModelName && relationshipName === this._lhsRelationshipName;
};
RelationshipPayloads.prototype._isRHS = function _isRHS(modelName, relationshipName) {
- var relInfo = this._relInfo;
- var isSelfReferential = relInfo.isSelfReferential;
- var isRelationship = relationshipName === relInfo.rhs_relationshipName;
-
- if (isRelationship === true) {
- return isSelfReferential === true || // itself
- modelName === relInfo.rhs_baseModelName || // base or non-polymorphic
- relInfo.rhs_modelNames.indexOf(modelName) !== -1; // polymorphic
- }
-
- return false;
+ return modelName === this._rhsModelName && relationshipName === this._rhsRelationshipName;
};
RelationshipPayloads.prototype._flushPending = function _flushPending() {
if (this._pendingPayloads.length === 0) {
return;
@@ -8350,32 +8211,30 @@
var inverseRelationshipData = {
data: {
id: id,
type: modelName
}
- };
- // start flushing this individual payload. The logic is the same whether
- // it's for the left hand side of the relationship or the right hand side,
- // except the role of primary and inverse idToPayloads is reversed
- //
- var previousPayload = void 0;
- var payloadMap = void 0;
- var inversePayloadMap = void 0;
+ // start flushing this individual payload. The logic is the same whether
+ // it's for the left hand side of the relationship or the right hand side,
+ // except the role of primary and inverse idToPayloads is reversed
+ //
+ };var previousPayload = void 0;
+ var idToPayloads = void 0;
+ var inverseIdToPayloads = void 0;
var inverseIsMany = void 0;
-
if (this._isLHS(modelName, relationshipName)) {
- previousPayload = this.lhs_payloads.get(modelName, id);
- payloadMap = this.lhs_payloads;
- inversePayloadMap = this.rhs_payloads;
+ previousPayload = this._lhsPayloads[id];
+ idToPayloads = this._lhsPayloads;
+ inverseIdToPayloads = this._rhsPayloads;
inverseIsMany = this._rhsRelationshipIsMany;
} else {
- (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._relInfo.lhs_key + '<->' + this._relInfo.rhs_key, this._isRHS(modelName, relationshipName)));
+ (false && Ember.assert(modelName + ':' + relationshipName + ' is not either side of this relationship, ' + this._lhsModelName + ':' + this._lhsRelationshipName + '<->' + this._rhsModelName + ':' + this._rhsRelationshipName, this._isRHS(modelName, relationshipName)));
- previousPayload = this.rhs_payloads.get(modelName, id);
- payloadMap = this.rhs_payloads;
- inversePayloadMap = this.lhs_payloads;
+ previousPayload = this._rhsPayloads[id];
+ idToPayloads = this._rhsPayloads;
+ inverseIdToPayloads = this._lhsPayloads;
inverseIsMany = this._lhsRelationshipIsMany;
}
// actually flush this individual payload
//
@@ -8415,69 +8274,67 @@
// only remove relationship information before adding if there is relationshipData.data
// * null is considered new information "empty", and it should win
// * undefined is NOT considered new information, we should keep original state
// * anything else is considered new information, and it should win
if (relationshipData.data !== undefined) {
- this._removeInverse(id, previousPayload, inversePayloadMap);
+ this._removeInverse(id, previousPayload, inverseIdToPayloads);
}
- payloadMap.set(modelName, id, relationshipData);
- this._populateInverse(relationshipData, inverseRelationshipData, inversePayloadMap, inverseIsMany);
+ idToPayloads[id] = relationshipData;
+ this._populateInverse(relationshipData, inverseRelationshipData, inverseIdToPayloads, inverseIsMany);
}
};
- RelationshipPayloads.prototype._populateInverse = function _populateInverse(relationshipData, inversePayload, inversePayloadMap, inverseIsMany) {
+ RelationshipPayloads.prototype._populateInverse = function _populateInverse(relationshipData, inversePayload, inverseIdToPayloads, inverseIsMany) {
if (!relationshipData.data) {
// This id doesn't have an inverse, eg a belongsTo with a payload
// { data: null }, so there's nothing to populate
return;
}
if (Array.isArray(relationshipData.data)) {
for (var i = 0; i < relationshipData.data.length; ++i) {
- var resourceIdentifier = relationshipData.data[i];
- this._addToInverse(inversePayload, resourceIdentifier, inversePayloadMap, inverseIsMany);
+ var inverseId = relationshipData.data[i].id;
+ this._addToInverse(inversePayload, inverseId, inverseIdToPayloads, inverseIsMany);
}
} else {
- var _resourceIdentifier = relationshipData.data;
- this._addToInverse(inversePayload, _resourceIdentifier, inversePayloadMap, inverseIsMany);
+ var _inverseId = relationshipData.data.id;
+ this._addToInverse(inversePayload, _inverseId, inverseIdToPayloads, inverseIsMany);
}
};
- RelationshipPayloads.prototype._addToInverse = function _addToInverse(inversePayload, resourceIdentifier, inversePayloadMap, inverseIsMany) {
- var relInfo = this._relInfo;
-
- if (relInfo.isReflexive && inversePayload.data.id === resourceIdentifier.id) {
+ RelationshipPayloads.prototype._addToInverse = function _addToInverse(inversePayload, inverseId, inverseIdToPayloads, inverseIsMany) {
+ if (this._isReflexive && inversePayload.data.id === inverseId) {
// eg <user:1>.friends = [{ id: 1, type: 'user' }]
return;
}
- var existingPayload = inversePayloadMap.get(resourceIdentifier.type, resourceIdentifier.id);
+ var existingPayload = inverseIdToPayloads[inverseId];
var existingData = existingPayload && existingPayload.data;
if (existingData) {
// There already is an inverse, either add or overwrite depehnding on
// whether the inverse is a many relationship or not
//
if (Array.isArray(existingData)) {
existingData.push(inversePayload.data);
} else {
- inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, inversePayload);
+ inverseIdToPayloads[inverseId] = inversePayload;
}
} else {
// first time we're populating the inverse side
//
if (inverseIsMany) {
- inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, {
+ inverseIdToPayloads[inverseId] = {
data: [inversePayload.data]
- });
+ };
} else {
- inversePayloadMap.set(resourceIdentifier.type, resourceIdentifier.id, inversePayload);
+ inverseIdToPayloads[inverseId] = inversePayload;
}
}
};
- RelationshipPayloads.prototype._removeInverse = function _removeInverse(id, previousPayload, inversePayloadMap) {
+ RelationshipPayloads.prototype._removeInverse = function _removeInverse(id, previousPayload, inverseIdToPayloads) {
var data = previousPayload && previousPayload.data;
if (!data) {
// either this is the first time we've seen a payload for this id, or its
// previous payload indicated that it had no inverse, eg a belongsTo
// relationship with payload { data: null }
@@ -8488,20 +8345,19 @@
}
if (Array.isArray(data)) {
// TODO: diff rather than removeall addall?
for (var i = 0; i < data.length; ++i) {
- var resourceIdentifier = data[i];
- this._removeFromInverse(id, resourceIdentifier, inversePayloadMap);
+ this._removeFromInverse(id, data[i].id, inverseIdToPayloads);
}
} else {
- this._removeFromInverse(id, data, inversePayloadMap);
+ this._removeFromInverse(id, data.id, inverseIdToPayloads);
}
};
- RelationshipPayloads.prototype._removeFromInverse = function _removeFromInverse(id, resourceIdentifier, inversePayloads) {
- var inversePayload = inversePayloads.get(resourceIdentifier.type, resourceIdentifier.id);
+ RelationshipPayloads.prototype._removeFromInverse = function _removeFromInverse(id, inverseId, inversePayloads) {
+ var inversePayload = inversePayloads[inverseId];
var data = inversePayload && inversePayload.data;
if (!data) {
return;
}
@@ -8509,27 +8365,25 @@
if (Array.isArray(data)) {
inversePayload.data = data.filter(function (x) {
return x.id !== id;
});
} else {
- inversePayloads.set(resourceIdentifier.type, resourceIdentifier.id, {
+ inversePayloads[inverseId] = {
data: null
- });
+ };
}
};
_createClass(RelationshipPayloads, [{
key: '_lhsRelationshipIsMany',
get: function () {
- var meta = this._relInfo.lhs_relationshipMeta;
- return meta !== null && meta.kind === 'hasMany';
+ return this._lhsRelationshipMeta && this._lhsRelationshipMeta.kind === 'hasMany';
}
}, {
key: '_rhsRelationshipIsMany',
get: function () {
- var meta = this._relInfo.rhs_relationshipMeta;
- return meta !== null && meta.kind === 'hasMany';
+ return this._rhsRelationshipMeta && this._rhsRelationshipMeta.kind === 'hasMany';
}
}]);
return RelationshipPayloads;
}();
@@ -10599,13 +10453,11 @@
(false && Ember.assert('You cannot pass \'' + id + '\' as id to the store\'s find method', typeof id === 'string' || typeof id === 'number'));
(false && Ember.assert('Calling store.find() with a query object is no longer supported. Use store.query() instead.', typeof id !== 'object'));
(false && Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + modelName, typeof modelName === 'string'));
- var normalizedModelName = (0, _normalizeModelName.default)(modelName);
-
- return this.findRecord(normalizedModelName, id);
+ return this.findRecord(modelName, id);
},
/**
This method returns a record for a given type and id combination.
@@ -16683,12 +16535,13 @@
serializeBelongsTo: function (snapshot, json, relationship) {
var key = relationship.key;
if (this._canSerialize(key)) {
var belongsTo = snapshot.belongsTo(key);
- if (belongsTo !== undefined) {
+ var belongsToIsNotNew = belongsTo && belongsTo.record && !belongsTo.record.get('isNew');
+ if (belongsTo === null || belongsToIsNotNew) {
json.relationships = json.relationships || {};
var payloadKey = this._getMappedKey(key, snapshot.type);
if (payloadKey === key) {
payloadKey = this.keyForRelationship(key, 'belongsTo', 'serialize');
@@ -18226,10 +18079,10 @@
});
define("ember-data/version", ["exports"], function (exports) {
"use strict";
exports.__esModule = true;
- exports.default = "3.0.2";
+ exports.default = "3.1.0-beta.1";
});
define("ember-inflector", ["module", "exports", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (module, exports, _system) {
"use strict";
exports.__esModule = true;