ember-data-source 1.0.0.beta.10 → 1.0.0.beta.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/dist/ember-data.js +571 -155
- data/dist/ember-data.min.js +3 -3
- data/dist/ember-data.named-amd.js +555 -155
- data/dist/ember-data.named-amd.min.js +3 -3
- data/dist/ember-data.named-amd.prod.js +540 -155
- data/dist/ember-data.prod.js +556 -155
- data/package.json +2 -2
- metadata +2 -2
data/dist/ember-data.prod.js
CHANGED
@@ -2,10 +2,26 @@
|
|
2
2
|
var define, requireModule, require, requirejs;
|
3
3
|
|
4
4
|
(function() {
|
5
|
+
|
6
|
+
var _isArray;
|
7
|
+
if (!Array.isArray) {
|
8
|
+
_isArray = function (x) {
|
9
|
+
return Object.prototype.toString.call(x) === "[object Array]";
|
10
|
+
};
|
11
|
+
} else {
|
12
|
+
_isArray = Array.isArray;
|
13
|
+
}
|
14
|
+
|
5
15
|
var registry = {}, seen = {}, state = {};
|
6
16
|
var FAILED = false;
|
7
17
|
|
8
18
|
define = function(name, deps, callback) {
|
19
|
+
|
20
|
+
if (!_isArray(deps)) {
|
21
|
+
callback = deps;
|
22
|
+
deps = [];
|
23
|
+
}
|
24
|
+
|
9
25
|
registry[name] = {
|
10
26
|
deps: deps,
|
11
27
|
callback: callback
|
@@ -274,7 +290,7 @@ define("activemodel-adapter/system/active_model_adapter",
|
|
274
290
|
https://tools.ietf.org/html/rfc4918#section-11.2
|
275
291
|
|
276
292
|
@method ajaxError
|
277
|
-
@param jqXHR
|
293
|
+
@param {Object} jqXHR
|
278
294
|
@return error
|
279
295
|
*/
|
280
296
|
ajaxError: function(jqXHR) {
|
@@ -463,7 +479,7 @@ define("activemodel-adapter/system/active_model_serializer",
|
|
463
479
|
@method serializePolymorphicType
|
464
480
|
@param {DS.Model} record
|
465
481
|
@param {Object} json
|
466
|
-
@param relationship
|
482
|
+
@param {Object} relationship
|
467
483
|
*/
|
468
484
|
serializePolymorphicType: function(record, json, relationship) {
|
469
485
|
var key = relationship.key;
|
@@ -1054,8 +1070,8 @@ define("ember-data/adapters/fixture_adapter",
|
|
1054
1070
|
});
|
1055
1071
|
});
|
1056
1072
|
define("ember-data/adapters/rest_adapter",
|
1057
|
-
["ember-data/system/adapter","exports"],
|
1058
|
-
function(__dependency1__, __exports__) {
|
1073
|
+
["ember-data/system/adapter","ember-data/system/map","exports"],
|
1074
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
1059
1075
|
"use strict";
|
1060
1076
|
/**
|
1061
1077
|
@module ember-data
|
@@ -1063,6 +1079,7 @@ define("ember-data/adapters/rest_adapter",
|
|
1063
1079
|
|
1064
1080
|
var Adapter = __dependency1__.Adapter;
|
1065
1081
|
var InvalidError = __dependency1__.InvalidError;
|
1082
|
+
var MapWithDefault = __dependency2__.MapWithDefault;
|
1066
1083
|
var get = Ember.get;
|
1067
1084
|
var forEach = Ember.ArrayPolyfills.forEach;
|
1068
1085
|
|
@@ -1262,6 +1279,9 @@ define("ember-data/adapters/rest_adapter",
|
|
1262
1279
|
|
1263
1280
|
will also send a request to: `GET /comments?ids[]=1&ids[]=2`
|
1264
1281
|
|
1282
|
+
Note: Requests coalescing rely on URL building strategy. So if you override `buildUrl` in your app
|
1283
|
+
`groupRecordsForFindMany` more likely should be overriden as well in order for coalescing to work.
|
1284
|
+
|
1265
1285
|
@property coalesceFindRequests
|
1266
1286
|
@type {boolean}
|
1267
1287
|
*/
|
@@ -1590,7 +1610,7 @@ define("ember-data/adapters/rest_adapter",
|
|
1590
1610
|
//We might get passed in an array of ids from findMany
|
1591
1611
|
//in which case we don't want to modify the url, as the
|
1592
1612
|
//ids will be passed in through a query param
|
1593
|
-
if (id && !Ember.isArray(id)) { url.push(id); }
|
1613
|
+
if (id && !Ember.isArray(id)) { url.push(encodeURIComponent(id)); }
|
1594
1614
|
|
1595
1615
|
if (prefix) { url.unshift(prefix); }
|
1596
1616
|
|
@@ -1675,7 +1695,7 @@ define("ember-data/adapters/rest_adapter",
|
|
1675
1695
|
loaded separately by `findMany`.
|
1676
1696
|
*/
|
1677
1697
|
groupRecordsForFindMany: function (store, records) {
|
1678
|
-
var groups =
|
1698
|
+
var groups = MapWithDefault.create({defaultValue: function(){return [];}});
|
1679
1699
|
var adapter = this;
|
1680
1700
|
|
1681
1701
|
forEach.call(records, function(record){
|
@@ -1705,7 +1725,7 @@ define("ember-data/adapters/rest_adapter",
|
|
1705
1725
|
}
|
1706
1726
|
|
1707
1727
|
var groupsArray = [];
|
1708
|
-
groups.forEach(function(
|
1728
|
+
groups.forEach(function(group, key){
|
1709
1729
|
// http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
|
1710
1730
|
var maxUrlLength = 2048;
|
1711
1731
|
var splitGroups = splitGroupToFitInUrl(group, maxUrlLength);
|
@@ -1924,11 +1944,11 @@ define("ember-data/core",
|
|
1924
1944
|
/**
|
1925
1945
|
@property VERSION
|
1926
1946
|
@type String
|
1927
|
-
@default '1.0.0-beta.
|
1947
|
+
@default '1.0.0-beta.11'
|
1928
1948
|
@static
|
1929
1949
|
*/
|
1930
1950
|
DS = Ember.Namespace.create({
|
1931
|
-
VERSION: '1.0.0-beta.
|
1951
|
+
VERSION: '1.0.0-beta.11'
|
1932
1952
|
});
|
1933
1953
|
|
1934
1954
|
if (Ember.libraries) {
|
@@ -2047,7 +2067,8 @@ define("ember-data/ext/date",
|
|
2047
2067
|
|
2048
2068
|
/**
|
2049
2069
|
@method parse
|
2050
|
-
@param date
|
2070
|
+
@param {Date} date
|
2071
|
+
@return {Number} timestamp
|
2051
2072
|
*/
|
2052
2073
|
Ember.Date.parse = function (date) {
|
2053
2074
|
var timestamp, struct, minutesOffset = 0;
|
@@ -2217,21 +2238,24 @@ define("ember-data/serializers/embedded_records_mixin",
|
|
2217
2238
|
```js
|
2218
2239
|
App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
|
2219
2240
|
attrs: {
|
2220
|
-
author: {embedded: 'always'},
|
2221
|
-
comments: {serialize: 'ids'}
|
2241
|
+
author: { embedded: 'always' },
|
2242
|
+
comments: { serialize: 'ids' }
|
2222
2243
|
}
|
2223
|
-
})
|
2244
|
+
});
|
2224
2245
|
```
|
2225
|
-
Note that this use of `{embedded: 'always'}` is unrelated to
|
2226
|
-
the `{embedded: 'always'}` that is defined as an option on `DS.attr` as part of
|
2246
|
+
Note that this use of `{ embedded: 'always' }` is unrelated to
|
2247
|
+
the `{ embedded: 'always' }` that is defined as an option on `DS.attr` as part of
|
2227
2248
|
defining a model while working with the ActiveModelSerializer. Nevertheless,
|
2228
|
-
using `{embedded: 'always'}` as an option to DS.attr is not a valid way to setup
|
2249
|
+
using `{ embedded: 'always' }` as an option to DS.attr is not a valid way to setup
|
2229
2250
|
embedded records.
|
2230
2251
|
|
2231
|
-
The `attrs` option for a resource `{embedded: 'always'}` is shorthand for:
|
2252
|
+
The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for:
|
2232
2253
|
|
2233
2254
|
```js
|
2234
|
-
{
|
2255
|
+
{
|
2256
|
+
serialize: 'records',
|
2257
|
+
deserialize: 'records'
|
2258
|
+
}
|
2235
2259
|
```
|
2236
2260
|
|
2237
2261
|
### Configuring Attrs
|
@@ -2255,8 +2279,8 @@ define("ember-data/serializers/embedded_records_mixin",
|
|
2255
2279
|
If you do not overwrite `attrs` for a specific relationship, the `EmbeddedRecordsMixin`
|
2256
2280
|
will behave in the following way:
|
2257
2281
|
|
2258
|
-
BelongsTo: `{serialize:'id', deserialize:'id'}`
|
2259
|
-
HasMany: `{serialize:false,
|
2282
|
+
BelongsTo: `{ serialize: 'id', deserialize: 'id' }`
|
2283
|
+
HasMany: `{ serialize: false, deserialize: 'ids' }`
|
2260
2284
|
|
2261
2285
|
### Model Relationships
|
2262
2286
|
|
@@ -3252,8 +3276,9 @@ define("ember-data/serializers/json_serializer",
|
|
3252
3276
|
payloadKey = this.keyForRelationship(key, "belongsTo");
|
3253
3277
|
}
|
3254
3278
|
|
3255
|
-
|
3256
|
-
|
3279
|
+
//Need to check whether the id is there for new&async records
|
3280
|
+
if (isNone(belongsTo) || isNone(get(belongsTo, 'id'))) {
|
3281
|
+
json[payloadKey] = null;
|
3257
3282
|
} else {
|
3258
3283
|
json[payloadKey] = get(belongsTo, 'id');
|
3259
3284
|
}
|
@@ -3760,7 +3785,7 @@ define("ember-data/serializers/rest_serializer",
|
|
3760
3785
|
@namespace DS
|
3761
3786
|
@extends DS.JSONSerializer
|
3762
3787
|
*/
|
3763
|
-
|
3788
|
+
var RESTSerializer = JSONSerializer.extend({
|
3764
3789
|
/**
|
3765
3790
|
If you want to do normalizations specific to some part of the payload, you
|
3766
3791
|
can specify those under `normalizeHash`.
|
@@ -3973,6 +3998,9 @@ define("ember-data/serializers/rest_serializer",
|
|
3973
3998
|
|
3974
3999
|
for (var prop in payload) {
|
3975
4000
|
var typeName = this.typeForRoot(prop);
|
4001
|
+
if (!store.modelFactoryFor(typeName)){
|
4002
|
+
continue;
|
4003
|
+
}
|
3976
4004
|
var type = store.modelFor(typeName);
|
3977
4005
|
var isPrimary = type.typeKey === primaryTypeName;
|
3978
4006
|
var value = payload[prop];
|
@@ -4126,6 +4154,9 @@ define("ember-data/serializers/rest_serializer",
|
|
4126
4154
|
}
|
4127
4155
|
|
4128
4156
|
var typeName = this.typeForRoot(typeKey);
|
4157
|
+
if (!store.modelFactoryFor(typeName)) {
|
4158
|
+
continue;
|
4159
|
+
}
|
4129
4160
|
var type = store.modelFor(typeName);
|
4130
4161
|
var typeSerializer = store.serializerFor(type);
|
4131
4162
|
var isPrimary = (!forcedSecondary && (type.typeKey === primaryTypeName));
|
@@ -4181,6 +4212,9 @@ define("ember-data/serializers/rest_serializer",
|
|
4181
4212
|
|
4182
4213
|
for (var prop in payload) {
|
4183
4214
|
var typeName = this.typeForRoot(prop);
|
4215
|
+
if (!store.modelFactoryFor(typeName, prop)){
|
4216
|
+
continue;
|
4217
|
+
}
|
4184
4218
|
var type = store.modelFor(typeName);
|
4185
4219
|
var typeSerializer = store.serializerFor(type);
|
4186
4220
|
|
@@ -4381,8 +4415,9 @@ define("ember-data/serializers/rest_serializer",
|
|
4381
4415
|
```
|
4382
4416
|
|
4383
4417
|
@method serialize
|
4384
|
-
@param record
|
4385
|
-
@param options
|
4418
|
+
@param {subclass of DS.Model} record
|
4419
|
+
@param {Object} options
|
4420
|
+
@return {Object} json
|
4386
4421
|
*/
|
4387
4422
|
serialize: function(record, options) {
|
4388
4423
|
return this._super.apply(this, arguments);
|
@@ -4435,6 +4470,9 @@ define("ember-data/serializers/rest_serializer",
|
|
4435
4470
|
}
|
4436
4471
|
}
|
4437
4472
|
});
|
4473
|
+
|
4474
|
+
|
4475
|
+
__exports__["default"] = RESTSerializer;
|
4438
4476
|
});
|
4439
4477
|
define("ember-data/setup-container",
|
4440
4478
|
["ember-data/initializers/store","ember-data/initializers/transforms","ember-data/initializers/store_injections","ember-data/initializers/data_adapter","activemodel-adapter/setup-container","exports"],
|
@@ -5028,7 +5066,7 @@ define("ember-data/system/debug/debug_adapter",
|
|
5028
5066
|
}];
|
5029
5067
|
var count = 0;
|
5030
5068
|
var self = this;
|
5031
|
-
get(type, 'attributes').forEach(function(
|
5069
|
+
get(type, 'attributes').forEach(function(meta, name) {
|
5032
5070
|
if (count++ > self.attributeLimit) { return false; }
|
5033
5071
|
var desc = capitalize(underscore(name).replace('_', ' '));
|
5034
5072
|
columns.push({ name: name, desc: desc });
|
@@ -5185,6 +5223,101 @@ define("ember-data/system/debug/debug_info",
|
|
5185
5223
|
|
5186
5224
|
__exports__["default"] = Model;
|
5187
5225
|
});
|
5226
|
+
define("ember-data/system/map",
|
5227
|
+
["exports"],
|
5228
|
+
function(__exports__) {
|
5229
|
+
"use strict";
|
5230
|
+
/**
|
5231
|
+
* Polyfill Ember.Map behavior for Ember <= 1.7
|
5232
|
+
* This can probably be removed before 1.0 final
|
5233
|
+
*/
|
5234
|
+
var mapForEach, deleteFn;
|
5235
|
+
|
5236
|
+
function OrderedSet(){
|
5237
|
+
Ember.OrderedSet.apply(this, arguments);
|
5238
|
+
}
|
5239
|
+
|
5240
|
+
function Map() {
|
5241
|
+
Ember.Map.apply(this, arguments);
|
5242
|
+
}
|
5243
|
+
|
5244
|
+
function MapWithDefault(){
|
5245
|
+
Ember.MapWithDefault.apply(this, arguments);
|
5246
|
+
}
|
5247
|
+
|
5248
|
+
var testMap = Ember.Map.create();
|
5249
|
+
testMap.set('key', 'value');
|
5250
|
+
|
5251
|
+
var usesOldBehavior = false;
|
5252
|
+
|
5253
|
+
testMap.forEach(function(value, key){
|
5254
|
+
usesOldBehavior = value === 'key' && key === 'value';
|
5255
|
+
});
|
5256
|
+
|
5257
|
+
Map.prototype = Object.create(Ember.Map.prototype);
|
5258
|
+
MapWithDefault.prototype = Object.create(Ember.MapWithDefault.prototype);
|
5259
|
+
OrderedSet.prototype = Object.create(Ember.OrderedSet.prototype);
|
5260
|
+
|
5261
|
+
OrderedSet.create = function(){
|
5262
|
+
return new OrderedSet();
|
5263
|
+
};
|
5264
|
+
|
5265
|
+
/**
|
5266
|
+
* returns a function that calls the original
|
5267
|
+
* callback function in the correct order.
|
5268
|
+
* if we are in pre-Ember.1.8 land, Map/MapWithDefault
|
5269
|
+
* forEach calls with key, value, in that order.
|
5270
|
+
* >= 1.8 forEach is called with the order value, key as per
|
5271
|
+
* the ES6 spec.
|
5272
|
+
*/
|
5273
|
+
function translate(valueKeyOrderedCallback){
|
5274
|
+
return function(key, value){
|
5275
|
+
valueKeyOrderedCallback.call(this, value, key);
|
5276
|
+
};
|
5277
|
+
}
|
5278
|
+
|
5279
|
+
// old, non ES6 compliant behavior
|
5280
|
+
if (usesOldBehavior){
|
5281
|
+
mapForEach = function(callback, thisArg){
|
5282
|
+
this.__super$forEach(translate(callback), thisArg);
|
5283
|
+
};
|
5284
|
+
|
5285
|
+
/* alias to remove */
|
5286
|
+
deleteFn = function(thing){
|
5287
|
+
this.remove(thing);
|
5288
|
+
};
|
5289
|
+
|
5290
|
+
Map.prototype.__super$forEach = Ember.Map.prototype.forEach;
|
5291
|
+
Map.prototype.forEach = mapForEach;
|
5292
|
+
Map.prototype["delete"] = deleteFn;
|
5293
|
+
|
5294
|
+
MapWithDefault.prototype.forEach = mapForEach;
|
5295
|
+
MapWithDefault.prototype.__super$forEach = Ember.MapWithDefault.prototype.forEach;
|
5296
|
+
MapWithDefault.prototype["delete"] = deleteFn;
|
5297
|
+
|
5298
|
+
OrderedSet.prototype["delete"] = deleteFn;
|
5299
|
+
}
|
5300
|
+
|
5301
|
+
MapWithDefault.constructor = MapWithDefault;
|
5302
|
+
Map.constructor = Map;
|
5303
|
+
|
5304
|
+
MapWithDefault.create = function(options){
|
5305
|
+
if (options) {
|
5306
|
+
return new MapWithDefault(options);
|
5307
|
+
} else {
|
5308
|
+
return new Map();
|
5309
|
+
}
|
5310
|
+
};
|
5311
|
+
|
5312
|
+
Map.create = function(){
|
5313
|
+
return new this.constructor();
|
5314
|
+
};
|
5315
|
+
|
5316
|
+
__exports__["default"] = Map;
|
5317
|
+
__exports__.Map = Map;
|
5318
|
+
__exports__.MapWithDefault = MapWithDefault;
|
5319
|
+
__exports__.OrderedSet = OrderedSet;
|
5320
|
+
});
|
5188
5321
|
define("ember-data/system/model",
|
5189
5322
|
["ember-data/system/model/model","ember-data/system/model/attributes","ember-data/system/model/states","ember-data/system/model/errors","exports"],
|
5190
5323
|
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) {
|
@@ -5204,10 +5337,11 @@ define("ember-data/system/model",
|
|
5204
5337
|
__exports__.Errors = Errors;
|
5205
5338
|
});
|
5206
5339
|
define("ember-data/system/model/attributes",
|
5207
|
-
["ember-data/system/model/model","exports"],
|
5208
|
-
function(__dependency1__, __exports__) {
|
5340
|
+
["ember-data/system/model/model","ember-data/system/map","exports"],
|
5341
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
5209
5342
|
"use strict";
|
5210
5343
|
var Model = __dependency1__["default"];
|
5344
|
+
var Map = __dependency2__.Map;
|
5211
5345
|
|
5212
5346
|
/**
|
5213
5347
|
@module ember-data
|
@@ -5253,7 +5387,7 @@ define("ember-data/system/model/attributes",
|
|
5253
5387
|
@readOnly
|
5254
5388
|
*/
|
5255
5389
|
attributes: Ember.computed(function() {
|
5256
|
-
var map =
|
5390
|
+
var map = Map.create();
|
5257
5391
|
|
5258
5392
|
this.eachComputedProperty(function(name, meta) {
|
5259
5393
|
if (meta.isAttribute) {
|
@@ -5298,7 +5432,7 @@ define("ember-data/system/model/attributes",
|
|
5298
5432
|
@readOnly
|
5299
5433
|
*/
|
5300
5434
|
transformedAttributes: Ember.computed(function() {
|
5301
|
-
var map =
|
5435
|
+
var map = Map.create();
|
5302
5436
|
|
5303
5437
|
this.eachAttribute(function(key, meta) {
|
5304
5438
|
if (meta.type) {
|
@@ -5351,7 +5485,7 @@ define("ember-data/system/model/attributes",
|
|
5351
5485
|
@static
|
5352
5486
|
*/
|
5353
5487
|
eachAttribute: function(callback, binding) {
|
5354
|
-
get(this, 'attributes').forEach(function(
|
5488
|
+
get(this, 'attributes').forEach(function(meta, name) {
|
5355
5489
|
callback.call(binding, name, meta);
|
5356
5490
|
}, binding);
|
5357
5491
|
},
|
@@ -5399,7 +5533,7 @@ define("ember-data/system/model/attributes",
|
|
5399
5533
|
@static
|
5400
5534
|
*/
|
5401
5535
|
eachTransformedAttribute: function(callback, binding) {
|
5402
|
-
get(this, 'transformedAttributes').forEach(function(
|
5536
|
+
get(this, 'transformedAttributes').forEach(function(type, name) {
|
5403
5537
|
callback.call(binding, name, type);
|
5404
5538
|
});
|
5405
5539
|
}
|
@@ -5512,13 +5646,15 @@ define("ember-data/system/model/attributes",
|
|
5512
5646
|
};
|
5513
5647
|
});
|
5514
5648
|
define("ember-data/system/model/errors",
|
5515
|
-
["exports"],
|
5516
|
-
function(__exports__) {
|
5649
|
+
["ember-data/system/map","exports"],
|
5650
|
+
function(__dependency1__, __exports__) {
|
5517
5651
|
"use strict";
|
5518
5652
|
var get = Ember.get;
|
5519
5653
|
var isEmpty = Ember.isEmpty;
|
5520
5654
|
var map = Ember.EnumerableUtils.map;
|
5521
5655
|
|
5656
|
+
var MapWithDefault = __dependency1__.MapWithDefault;
|
5657
|
+
|
5522
5658
|
/**
|
5523
5659
|
@module ember-data
|
5524
5660
|
*/
|
@@ -5615,7 +5751,7 @@ define("ember-data/system/model/errors",
|
|
5615
5751
|
*/
|
5616
5752
|
errorsByAttributeName: Ember.reduceComputed("content", {
|
5617
5753
|
initialValue: function() {
|
5618
|
-
return
|
5754
|
+
return MapWithDefault.create({
|
5619
5755
|
defaultValue: function() {
|
5620
5756
|
return Ember.A();
|
5621
5757
|
}
|
@@ -6307,6 +6443,27 @@ define("ember-data/system/model/model",
|
|
6307
6443
|
this._attributes = {};
|
6308
6444
|
this._inFlightAttributes = {};
|
6309
6445
|
this._relationships = {};
|
6446
|
+
/*
|
6447
|
+
implicit relationships are relationship which have not been declared but the inverse side exists on
|
6448
|
+
another record somewhere
|
6449
|
+
For example if there was
|
6450
|
+
```
|
6451
|
+
App.Comment = DS.Model.extend({
|
6452
|
+
name: DS.attr()
|
6453
|
+
})
|
6454
|
+
```
|
6455
|
+
but there is also
|
6456
|
+
```
|
6457
|
+
App.Post = DS.Model.extend({
|
6458
|
+
name: DS.attr(),
|
6459
|
+
comments: DS.hasMany('comment')
|
6460
|
+
})
|
6461
|
+
```
|
6462
|
+
|
6463
|
+
would have a implicit post relationship in order to be do things like remove ourselves from the post
|
6464
|
+
when we are deleted
|
6465
|
+
*/
|
6466
|
+
this._implicitRelationships = Object.create(null);
|
6310
6467
|
var model = this;
|
6311
6468
|
//TODO Move into a getter for better perf
|
6312
6469
|
this.constructor.eachRelationship(function(key, descriptor) {
|
@@ -6504,6 +6661,27 @@ define("ember-data/system/model/model",
|
|
6504
6661
|
}, this);
|
6505
6662
|
},
|
6506
6663
|
|
6664
|
+
disconnectRelationships: function() {
|
6665
|
+
this.eachRelationship(function(name, relationship) {
|
6666
|
+
this._relationships[name].disconnect();
|
6667
|
+
}, this);
|
6668
|
+
var model = this;
|
6669
|
+
forEach.call(Ember.keys(this._implicitRelationships), function(key) {
|
6670
|
+
model._implicitRelationships[key].disconnect();
|
6671
|
+
});
|
6672
|
+
},
|
6673
|
+
|
6674
|
+
reconnectRelationships: function() {
|
6675
|
+
this.eachRelationship(function(name, relationship) {
|
6676
|
+
this._relationships[name].reconnect();
|
6677
|
+
}, this);
|
6678
|
+
var model = this;
|
6679
|
+
forEach.call(Ember.keys(this._implicitRelationships), function(key) {
|
6680
|
+
model._implicitRelationships[key].reconnect();
|
6681
|
+
});
|
6682
|
+
},
|
6683
|
+
|
6684
|
+
|
6507
6685
|
/**
|
6508
6686
|
@method updateRecordArrays
|
6509
6687
|
@private
|
@@ -6723,6 +6901,13 @@ define("ember-data/system/model/model",
|
|
6723
6901
|
set(this, 'isError', false);
|
6724
6902
|
}
|
6725
6903
|
|
6904
|
+
//Eventually rollback will always work for relationships
|
6905
|
+
//For now we support it only out of deleted state, because we
|
6906
|
+
//have an explicit way of knowing when the server acked the relationship change
|
6907
|
+
if (get(this, 'isDeleted')) {
|
6908
|
+
this.reconnectRelationships();
|
6909
|
+
}
|
6910
|
+
|
6726
6911
|
if (!get(this, 'isValid')) {
|
6727
6912
|
this._inFlightAttributes = {};
|
6728
6913
|
}
|
@@ -6738,7 +6923,7 @@ define("ember-data/system/model/model",
|
|
6738
6923
|
|
6739
6924
|
/**
|
6740
6925
|
Save the record and persist any changes to the record to an
|
6741
|
-
|
6926
|
+
external source via the adapter.
|
6742
6927
|
|
6743
6928
|
Example
|
6744
6929
|
|
@@ -6805,7 +6990,9 @@ define("ember-data/system/model/model",
|
|
6805
6990
|
}, function(reason) {
|
6806
6991
|
record.set('isError', true);
|
6807
6992
|
throw reason;
|
6808
|
-
}, "DS: Model#reload complete, update flags")
|
6993
|
+
}, "DS: Model#reload complete, update flags")['finally'](function () {
|
6994
|
+
record.updateRecordArrays();
|
6995
|
+
});
|
6809
6996
|
|
6810
6997
|
return PromiseObject.create({
|
6811
6998
|
promise: promise
|
@@ -6861,15 +7048,32 @@ define("ember-data/system/model/model",
|
|
6861
7048
|
|
6862
7049
|
@method trigger
|
6863
7050
|
@private
|
6864
|
-
@param name
|
7051
|
+
@param {String} name
|
6865
7052
|
*/
|
6866
|
-
trigger: function(
|
6867
|
-
|
7053
|
+
trigger: function() {
|
7054
|
+
var length = arguments.length;
|
7055
|
+
var args = new Array(length - 1);
|
7056
|
+
var name = arguments[0];
|
7057
|
+
|
7058
|
+
for (var i = 1; i < length; i++ ){
|
7059
|
+
args[i - 1] = arguments[i];
|
7060
|
+
}
|
7061
|
+
|
7062
|
+
Ember.tryInvoke(this, name, args);
|
6868
7063
|
this._super.apply(this, arguments);
|
6869
7064
|
},
|
6870
7065
|
|
6871
7066
|
triggerLater: function() {
|
6872
|
-
|
7067
|
+
var length = arguments.length;
|
7068
|
+
var args = new Array(length);
|
7069
|
+
|
7070
|
+
for (var i = 0; i < length; i++ ){
|
7071
|
+
args[i] = arguments[i];
|
7072
|
+
}
|
7073
|
+
|
7074
|
+
if (this._deferredTriggers.push(args) !== 1) {
|
7075
|
+
return;
|
7076
|
+
}
|
6873
7077
|
Ember.run.schedule('actions', this, '_triggerDeferredTriggers');
|
6874
7078
|
},
|
6875
7079
|
|
@@ -7251,7 +7455,7 @@ define("ember-data/system/model/states",
|
|
7251
7455
|
// EVENTS
|
7252
7456
|
deleteRecord: function(record) {
|
7253
7457
|
record.transitionTo('deleted.uncommitted');
|
7254
|
-
record.
|
7458
|
+
record.disconnectRelationships();
|
7255
7459
|
},
|
7256
7460
|
|
7257
7461
|
didSetProperty: function(record, context) {
|
@@ -7332,7 +7536,7 @@ define("ember-data/system/model/states",
|
|
7332
7536
|
});
|
7333
7537
|
|
7334
7538
|
createdState.uncommitted.deleteRecord = function(record) {
|
7335
|
-
record.
|
7539
|
+
record.disconnectRelationships();
|
7336
7540
|
record.transitionTo('deleted.saved');
|
7337
7541
|
};
|
7338
7542
|
|
@@ -7350,7 +7554,7 @@ define("ember-data/system/model/states",
|
|
7350
7554
|
|
7351
7555
|
updatedState.uncommitted.deleteRecord = function(record) {
|
7352
7556
|
record.transitionTo('deleted.uncommitted');
|
7353
|
-
record.
|
7557
|
+
record.disconnectRelationships();
|
7354
7558
|
};
|
7355
7559
|
|
7356
7560
|
var RootState = {
|
@@ -7491,7 +7695,7 @@ define("ember-data/system/model/states",
|
|
7491
7695
|
|
7492
7696
|
deleteRecord: function(record) {
|
7493
7697
|
record.transitionTo('deleted.uncommitted');
|
7494
|
-
record.
|
7698
|
+
record.disconnectRelationships();
|
7495
7699
|
},
|
7496
7700
|
|
7497
7701
|
unloadRecord: function(record) {
|
@@ -7648,6 +7852,7 @@ define("ember-data/system/promise_proxies",
|
|
7648
7852
|
function(__exports__) {
|
7649
7853
|
"use strict";
|
7650
7854
|
var Promise = Ember.RSVP.Promise;
|
7855
|
+
var get = Ember.get;
|
7651
7856
|
|
7652
7857
|
/**
|
7653
7858
|
A `PromiseArray` is an object that acts like both an `Ember.Array`
|
@@ -7723,14 +7928,37 @@ define("ember-data/system/promise_proxies",
|
|
7723
7928
|
});
|
7724
7929
|
};
|
7725
7930
|
|
7931
|
+
/**
|
7932
|
+
A PromiseManyArray is a PromiseArray that also proxies certain method calls
|
7933
|
+
to the underlying manyArray.
|
7934
|
+
Right now we proxy:
|
7935
|
+
`reload()`
|
7936
|
+
*/
|
7937
|
+
|
7938
|
+
var PromiseManyArray = PromiseArray.extend({
|
7939
|
+
reload: function() {
|
7940
|
+
//I don't think this should ever happen right now, but worth guarding if we refactor the async relationships
|
7941
|
+
return get(this, 'content').reload();
|
7942
|
+
}
|
7943
|
+
});
|
7944
|
+
|
7945
|
+
var promiseManyArray = function(promise, label) {
|
7946
|
+
return PromiseManyArray.create({
|
7947
|
+
promise: Promise.resolve(promise, label)
|
7948
|
+
});
|
7949
|
+
};
|
7950
|
+
|
7951
|
+
|
7726
7952
|
__exports__.PromiseArray = PromiseArray;
|
7727
7953
|
__exports__.PromiseObject = PromiseObject;
|
7954
|
+
__exports__.PromiseManyArray = PromiseManyArray;
|
7728
7955
|
__exports__.promiseArray = promiseArray;
|
7729
7956
|
__exports__.promiseObject = promiseObject;
|
7957
|
+
__exports__.promiseManyArray = promiseManyArray;
|
7730
7958
|
});
|
7731
7959
|
define("ember-data/system/record_array_manager",
|
7732
|
-
["ember-data/system/record_arrays","exports"],
|
7733
|
-
function(__dependency1__, __exports__) {
|
7960
|
+
["ember-data/system/record_arrays","ember-data/system/map","exports"],
|
7961
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
7734
7962
|
"use strict";
|
7735
7963
|
/**
|
7736
7964
|
@module ember-data
|
@@ -7740,6 +7968,8 @@ define("ember-data/system/record_array_manager",
|
|
7740
7968
|
var FilteredRecordArray = __dependency1__.FilteredRecordArray;
|
7741
7969
|
var AdapterPopulatedRecordArray = __dependency1__.AdapterPopulatedRecordArray;
|
7742
7970
|
var ManyArray = __dependency1__.ManyArray;
|
7971
|
+
var MapWithDefault = __dependency2__.MapWithDefault;
|
7972
|
+
var OrderedSet = __dependency2__.OrderedSet;
|
7743
7973
|
var get = Ember.get;
|
7744
7974
|
var forEach = Ember.EnumerableUtils.forEach;
|
7745
7975
|
|
@@ -7751,7 +7981,7 @@ define("ember-data/system/record_array_manager",
|
|
7751
7981
|
*/
|
7752
7982
|
__exports__["default"] = Ember.Object.extend({
|
7753
7983
|
init: function() {
|
7754
|
-
this.filteredRecordArrays =
|
7984
|
+
this.filteredRecordArrays = MapWithDefault.create({
|
7755
7985
|
defaultValue: function() { return []; }
|
7756
7986
|
});
|
7757
7987
|
|
@@ -7766,7 +7996,7 @@ define("ember-data/system/record_array_manager",
|
|
7766
7996
|
},
|
7767
7997
|
|
7768
7998
|
recordArraysForRecord: function(record) {
|
7769
|
-
record._recordArrays = record._recordArrays ||
|
7999
|
+
record._recordArrays = record._recordArrays || OrderedSet.create();
|
7770
8000
|
return record._recordArrays;
|
7771
8001
|
},
|
7772
8002
|
|
@@ -7799,9 +8029,11 @@ define("ember-data/system/record_array_manager",
|
|
7799
8029
|
|
7800
8030
|
if (!recordArrays) { return; }
|
7801
8031
|
|
7802
|
-
forEach(
|
8032
|
+
recordArrays.forEach(function(array){
|
7803
8033
|
array.removeRecord(record);
|
7804
8034
|
});
|
8035
|
+
|
8036
|
+
record._recordArrays = null;
|
7805
8037
|
},
|
7806
8038
|
|
7807
8039
|
_recordWasChanged: function (record) {
|
@@ -7853,7 +8085,7 @@ define("ember-data/system/record_array_manager",
|
|
7853
8085
|
recordArrays.add(array);
|
7854
8086
|
}
|
7855
8087
|
} else if (!shouldBeInArray) {
|
7856
|
-
recordArrays
|
8088
|
+
recordArrays["delete"](array);
|
7857
8089
|
array.removeRecord(record);
|
7858
8090
|
}
|
7859
8091
|
},
|
@@ -7866,9 +8098,9 @@ define("ember-data/system/record_array_manager",
|
|
7866
8098
|
method is invoked when the filter is created in th first place.
|
7867
8099
|
|
7868
8100
|
@method updateFilter
|
7869
|
-
@param array
|
7870
|
-
@param type
|
7871
|
-
@param filter
|
8101
|
+
@param {Array} array
|
8102
|
+
@param {String} type
|
8103
|
+
@param {Function} filter
|
7872
8104
|
*/
|
7873
8105
|
updateFilter: function(array, type, filter) {
|
7874
8106
|
var typeMap = this.store.typeMapFor(type);
|
@@ -8242,22 +8474,6 @@ define("ember-data/system/record_arrays/many_array",
|
|
8242
8474
|
this._super.apply(this, arguments);
|
8243
8475
|
},
|
8244
8476
|
|
8245
|
-
/**
|
8246
|
-
The property name of the relationship
|
8247
|
-
|
8248
|
-
@property {String} name
|
8249
|
-
@private
|
8250
|
-
*/
|
8251
|
-
name: null,
|
8252
|
-
|
8253
|
-
/**
|
8254
|
-
The record to which this relationship belongs.
|
8255
|
-
|
8256
|
-
@property {DS.Model} owner
|
8257
|
-
@private
|
8258
|
-
*/
|
8259
|
-
owner: null,
|
8260
|
-
|
8261
8477
|
/**
|
8262
8478
|
`true` if the relationship is polymorphic, `false` otherwise.
|
8263
8479
|
|
@@ -8320,6 +8536,13 @@ define("ember-data/system/record_arrays/many_array",
|
|
8320
8536
|
this.get('relationship').addRecords(objects, idx);
|
8321
8537
|
}
|
8322
8538
|
},
|
8539
|
+
/**
|
8540
|
+
@method reload
|
8541
|
+
@public
|
8542
|
+
*/
|
8543
|
+
reload: function() {
|
8544
|
+
return this.relationship.reload();
|
8545
|
+
},
|
8323
8546
|
|
8324
8547
|
/**
|
8325
8548
|
Create a child record within the owner
|
@@ -8539,7 +8762,7 @@ define("ember-data/system/record_arrays/record_array",
|
|
8539
8762
|
var recordArrays = record._recordArrays;
|
8540
8763
|
|
8541
8764
|
if (recordArrays) {
|
8542
|
-
recordArrays
|
8765
|
+
recordArrays["delete"](array);
|
8543
8766
|
}
|
8544
8767
|
});
|
8545
8768
|
},
|
@@ -8676,7 +8899,11 @@ define("ember-data/system/relationships/belongs_to",
|
|
8676
8899
|
if ( value === undefined ) {
|
8677
8900
|
value = null;
|
8678
8901
|
}
|
8679
|
-
|
8902
|
+
if (value && value.then) {
|
8903
|
+
this._relationships[key].setRecordPromise(value);
|
8904
|
+
} else {
|
8905
|
+
this._relationships[key].setRecord(value);
|
8906
|
+
}
|
8680
8907
|
}
|
8681
8908
|
|
8682
8909
|
return this._relationships[key].getRecord();
|
@@ -8703,14 +8930,17 @@ define("ember-data/system/relationships/belongs_to",
|
|
8703
8930
|
__exports__["default"] = belongsTo;
|
8704
8931
|
});
|
8705
8932
|
define("ember-data/system/relationships/ext",
|
8706
|
-
["ember-data/system/relationship-meta","ember-data/system/model"],
|
8707
|
-
function(__dependency1__, __dependency2__) {
|
8933
|
+
["ember-data/system/relationship-meta","ember-data/system/model","ember-data/system/map"],
|
8934
|
+
function(__dependency1__, __dependency2__, __dependency3__) {
|
8708
8935
|
"use strict";
|
8709
8936
|
var typeForRelationshipMeta = __dependency1__.typeForRelationshipMeta;
|
8710
8937
|
var relationshipFromMeta = __dependency1__.relationshipFromMeta;
|
8711
8938
|
var Model = __dependency2__.Model;
|
8939
|
+
var Map = __dependency3__.Map;
|
8940
|
+
var MapWithDefault = __dependency3__.MapWithDefault;
|
8712
8941
|
|
8713
8942
|
var get = Ember.get;
|
8943
|
+
var filter = Ember.ArrayPolyfills.filter;
|
8714
8944
|
|
8715
8945
|
/**
|
8716
8946
|
@module ember-data
|
@@ -8749,9 +8979,9 @@ define("ember-data/system/relationships/ext",
|
|
8749
8979
|
property returned by `DS.belongsTo` as the value.
|
8750
8980
|
|
8751
8981
|
@method didDefineProperty
|
8752
|
-
@param proto
|
8753
|
-
@param key
|
8754
|
-
@param value
|
8982
|
+
@param {Object} proto
|
8983
|
+
@param {String} key
|
8984
|
+
@param {Ember.ComputedProperty} value
|
8755
8985
|
*/
|
8756
8986
|
didDefineProperty: function(proto, key, value) {
|
8757
8987
|
// Check if the value being set is a computed property.
|
@@ -8785,6 +9015,7 @@ define("ember-data/system/relationships/ext",
|
|
8785
9015
|
*/
|
8786
9016
|
|
8787
9017
|
Model.reopenClass({
|
9018
|
+
|
8788
9019
|
/**
|
8789
9020
|
For a given relationship name, returns the model type of the relationship.
|
8790
9021
|
|
@@ -8808,17 +9039,59 @@ define("ember-data/system/relationships/ext",
|
|
8808
9039
|
return relationship && relationship.type;
|
8809
9040
|
},
|
8810
9041
|
|
9042
|
+
inverseMap: Ember.computed(function() {
|
9043
|
+
return Object.create(null);
|
9044
|
+
}),
|
9045
|
+
|
9046
|
+
/*
|
9047
|
+
Find the relationship which is the inverse of the one asked for.
|
9048
|
+
|
9049
|
+
For example, if you define models like this:
|
9050
|
+
|
9051
|
+
```javascript
|
9052
|
+
App.Post = DS.Model.extend({
|
9053
|
+
comments: DS.hasMany('message')
|
9054
|
+
});
|
9055
|
+
|
9056
|
+
App.Message = DS.Model.extend({
|
9057
|
+
owner: DS.belongsTo('post')
|
9058
|
+
});
|
9059
|
+
```
|
9060
|
+
|
9061
|
+
App.Post.inverseFor('comments') -> {type: App.Message, name:'owner', kind:'belongsTo'}
|
9062
|
+
App.Message.inverseFor('owner') -> {type: App.Post, name:'comments', kind:'hasMany'}
|
9063
|
+
|
9064
|
+
@method inverseFor
|
9065
|
+
@static
|
9066
|
+
@param {String} name the name of the relationship
|
9067
|
+
@return {Object} the inverse relationship, or null
|
9068
|
+
*/
|
8811
9069
|
inverseFor: function(name) {
|
8812
|
-
var
|
9070
|
+
var inverseMap = get(this, 'inverseMap');
|
9071
|
+
if (inverseMap[name]) {
|
9072
|
+
return inverseMap[name];
|
9073
|
+
} else {
|
9074
|
+
var inverse = this._findInverseFor(name);
|
9075
|
+
inverseMap[name] = inverse;
|
9076
|
+
return inverse;
|
9077
|
+
}
|
9078
|
+
},
|
8813
9079
|
|
8814
|
-
|
9080
|
+
//Calculate the inverse, ignoring the cache
|
9081
|
+
_findInverseFor: function(name) {
|
8815
9082
|
|
8816
|
-
var
|
9083
|
+
var inverseType = this.typeForRelationship(name);
|
9084
|
+
if (!inverseType) {
|
9085
|
+
return null;
|
9086
|
+
}
|
8817
9087
|
|
9088
|
+
//If inverse is manually specified to be null, like `comments: DS.hasMany('message', {inverse: null})`
|
9089
|
+
var options = this.metaForProperty(name).options;
|
8818
9090
|
if (options.inverse === null) { return null; }
|
8819
9091
|
|
8820
9092
|
var inverseName, inverseKind, inverse;
|
8821
9093
|
|
9094
|
+
//If inverse is specified manually, return the inverse
|
8822
9095
|
if (options.inverse) {
|
8823
9096
|
inverseName = options.inverse;
|
8824
9097
|
inverse = Ember.get(inverseType, 'relationshipsByName').get(inverseName);
|
@@ -8826,26 +9099,49 @@ define("ember-data/system/relationships/ext",
|
|
8826
9099
|
|
8827
9100
|
inverseKind = inverse.kind;
|
8828
9101
|
} else {
|
9102
|
+
//No inverse was specified manually, we need to use a heuristic to guess one
|
8829
9103
|
var possibleRelationships = findPossibleInverses(this, inverseType);
|
8830
9104
|
|
8831
9105
|
if (possibleRelationships.length === 0) { return null; }
|
8832
9106
|
|
9107
|
+
var filteredRelationships = filter.call(possibleRelationships, function(possibleRelationship) {
|
9108
|
+
var optionsForRelationship = inverseType.metaForProperty(possibleRelationship.name).options;
|
9109
|
+
return name === optionsForRelationship.inverse;
|
9110
|
+
});
|
9111
|
+
|
9112
|
+
|
9113
|
+
if (filteredRelationships.length === 1 ) {
|
9114
|
+
possibleRelationships = filteredRelationships;
|
9115
|
+
}
|
9116
|
+
|
8833
9117
|
|
8834
9118
|
inverseName = possibleRelationships[0].name;
|
8835
9119
|
inverseKind = possibleRelationships[0].kind;
|
8836
9120
|
}
|
8837
9121
|
|
8838
|
-
function findPossibleInverses(type, inverseType,
|
8839
|
-
possibleRelationships =
|
9122
|
+
function findPossibleInverses(type, inverseType, relationshipsSoFar) {
|
9123
|
+
var possibleRelationships = relationshipsSoFar || [];
|
8840
9124
|
|
8841
9125
|
var relationshipMap = get(inverseType, 'relationships');
|
8842
9126
|
if (!relationshipMap) { return; }
|
8843
9127
|
|
8844
9128
|
var relationships = relationshipMap.get(type);
|
9129
|
+
|
9130
|
+
relationships = filter.call(relationships, function(relationship) {
|
9131
|
+
var optionsForRelationship = inverseType.metaForProperty(relationship.name).options;
|
9132
|
+
|
9133
|
+
if (!optionsForRelationship.inverse){
|
9134
|
+
return true;
|
9135
|
+
}
|
9136
|
+
|
9137
|
+
return name === optionsForRelationship.inverse;
|
9138
|
+
});
|
9139
|
+
|
8845
9140
|
if (relationships) {
|
8846
|
-
possibleRelationships.push.apply(possibleRelationships,
|
9141
|
+
possibleRelationships.push.apply(possibleRelationships, relationships);
|
8847
9142
|
}
|
8848
9143
|
|
9144
|
+
//Recurse to support polymorphism
|
8849
9145
|
if (type.superclass) {
|
8850
9146
|
findPossibleInverses(type.superclass, inverseType, possibleRelationships);
|
8851
9147
|
}
|
@@ -8894,7 +9190,7 @@ define("ember-data/system/relationships/ext",
|
|
8894
9190
|
@readOnly
|
8895
9191
|
*/
|
8896
9192
|
relationships: Ember.computed(function() {
|
8897
|
-
var map = new
|
9193
|
+
var map = new MapWithDefault({
|
8898
9194
|
defaultValue: function() { return []; }
|
8899
9195
|
});
|
8900
9196
|
|
@@ -9042,7 +9338,7 @@ define("ember-data/system/relationships/ext",
|
|
9042
9338
|
@readOnly
|
9043
9339
|
*/
|
9044
9340
|
relationshipsByName: Ember.computed(function() {
|
9045
|
-
var map =
|
9341
|
+
var map = Map.create();
|
9046
9342
|
|
9047
9343
|
this.eachComputedProperty(function(name, meta) {
|
9048
9344
|
if (meta.isRelationship) {
|
@@ -9092,7 +9388,7 @@ define("ember-data/system/relationships/ext",
|
|
9092
9388
|
@readOnly
|
9093
9389
|
*/
|
9094
9390
|
fields: Ember.computed(function() {
|
9095
|
-
var map =
|
9391
|
+
var map = Map.create();
|
9096
9392
|
|
9097
9393
|
this.eachComputedProperty(function(name, meta) {
|
9098
9394
|
if (meta.isRelationship) {
|
@@ -9116,7 +9412,7 @@ define("ember-data/system/relationships/ext",
|
|
9116
9412
|
@param {any} binding the value to which the callback's `this` should be bound
|
9117
9413
|
*/
|
9118
9414
|
eachRelationship: function(callback, binding) {
|
9119
|
-
get(this, 'relationshipsByName').forEach(function(
|
9415
|
+
get(this, 'relationshipsByName').forEach(function(relationship, name) {
|
9120
9416
|
callback.call(binding, name, relationship);
|
9121
9417
|
});
|
9122
9418
|
},
|
@@ -9320,14 +9616,15 @@ define("ember-data/system/relationships/has_many",
|
|
9320
9616
|
__exports__["default"] = hasMany;
|
9321
9617
|
});
|
9322
9618
|
define("ember-data/system/relationships/relationship",
|
9323
|
-
["ember-data/system/promise_proxies","exports"],
|
9324
|
-
function(__dependency1__, __exports__) {
|
9619
|
+
["ember-data/system/promise_proxies","ember-data/system/map","exports"],
|
9620
|
+
function(__dependency1__, __dependency2__, __exports__) {
|
9325
9621
|
"use strict";
|
9326
|
-
var
|
9622
|
+
var PromiseManyArray = __dependency1__.PromiseManyArray;
|
9327
9623
|
var PromiseObject = __dependency1__.PromiseObject;
|
9624
|
+
var OrderedSet = __dependency2__.OrderedSet;
|
9328
9625
|
|
9329
9626
|
var Relationship = function(store, record, inverseKey, relationshipMeta) {
|
9330
|
-
this.members = new
|
9627
|
+
this.members = new OrderedSet();
|
9331
9628
|
this.store = store;
|
9332
9629
|
this.key = relationshipMeta.key;
|
9333
9630
|
this.inverseKey = inverseKey;
|
@@ -9335,11 +9632,15 @@ define("ember-data/system/relationships/relationship",
|
|
9335
9632
|
this.key = relationshipMeta.key;
|
9336
9633
|
this.isAsync = relationshipMeta.options.async;
|
9337
9634
|
this.relationshipMeta = relationshipMeta;
|
9635
|
+
//This probably breaks for polymorphic relationship in complex scenarios, due to
|
9636
|
+
//multiple possible typeKeys
|
9637
|
+
this.inverseKeyForImplicit = this.store.modelFor(this.record.constructor).typeKey + this.key;
|
9638
|
+
//Cached promise when fetching the relationship from a link
|
9639
|
+
this.linkPromise = null;
|
9338
9640
|
};
|
9339
9641
|
|
9340
9642
|
Relationship.prototype = {
|
9341
9643
|
constructor: Relationship,
|
9342
|
-
hasFetchedLink: false,
|
9343
9644
|
|
9344
9645
|
destroy: Ember.K,
|
9345
9646
|
|
@@ -9349,6 +9650,18 @@ define("ember-data/system/relationships/relationship",
|
|
9349
9650
|
}, this);
|
9350
9651
|
},
|
9351
9652
|
|
9653
|
+
disconnect: function(){
|
9654
|
+
this.members.forEach(function(member) {
|
9655
|
+
this.removeRecordFromInverse(member);
|
9656
|
+
}, this);
|
9657
|
+
},
|
9658
|
+
|
9659
|
+
reconnect: function(){
|
9660
|
+
this.members.forEach(function(member) {
|
9661
|
+
this.addRecordToInverse(member);
|
9662
|
+
}, this);
|
9663
|
+
},
|
9664
|
+
|
9352
9665
|
removeRecords: function(records){
|
9353
9666
|
var that = this;
|
9354
9667
|
records.forEach(function(record){
|
@@ -9366,13 +9679,17 @@ define("ember-data/system/relationships/relationship",
|
|
9366
9679
|
});
|
9367
9680
|
},
|
9368
9681
|
|
9369
|
-
|
9370
9682
|
addRecord: function(record, idx) {
|
9371
9683
|
if (!this.members.has(record)) {
|
9372
9684
|
this.members.add(record);
|
9373
9685
|
this.notifyRecordRelationshipAdded(record, idx);
|
9374
9686
|
if (this.inverseKey) {
|
9375
9687
|
record._relationships[this.inverseKey].addRecord(this.record);
|
9688
|
+
} else {
|
9689
|
+
if (!record._implicitRelationships[this.inverseKeyForImplicit]) {
|
9690
|
+
record._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, record, this.key, {options:{}});
|
9691
|
+
}
|
9692
|
+
record._implicitRelationships[this.inverseKeyForImplicit].addRecord(this.record);
|
9376
9693
|
}
|
9377
9694
|
this.record.updateRecordArrays();
|
9378
9695
|
}
|
@@ -9380,31 +9697,64 @@ define("ember-data/system/relationships/relationship",
|
|
9380
9697
|
|
9381
9698
|
removeRecord: function(record) {
|
9382
9699
|
if (this.members.has(record)) {
|
9383
|
-
this.
|
9384
|
-
this.notifyRecordRelationshipRemoved(record);
|
9700
|
+
this.removeRecordFromOwn(record);
|
9385
9701
|
if (this.inverseKey) {
|
9386
|
-
|
9387
|
-
|
9388
|
-
if (
|
9389
|
-
|
9702
|
+
this.removeRecordFromInverse(record);
|
9703
|
+
} else {
|
9704
|
+
if (record._implicitRelationships[this.inverseKeyForImplicit]) {
|
9705
|
+
record._implicitRelationships[this.inverseKeyForImplicit].removeRecord(this.record);
|
9390
9706
|
}
|
9391
9707
|
}
|
9392
|
-
this.record.updateRecordArrays();
|
9393
9708
|
}
|
9394
9709
|
},
|
9395
9710
|
|
9711
|
+
addRecordToInverse: function(record) {
|
9712
|
+
if (this.inverseKey) {
|
9713
|
+
record._relationships[this.inverseKey].addRecord(this.record);
|
9714
|
+
}
|
9715
|
+
},
|
9716
|
+
|
9717
|
+
removeRecordFromInverse: function(record) {
|
9718
|
+
var inverseRelationship = record._relationships[this.inverseKey];
|
9719
|
+
//Need to check for existence, as the record might unloading at the moment
|
9720
|
+
if (inverseRelationship) {
|
9721
|
+
inverseRelationship.removeRecordFromOwn(this.record);
|
9722
|
+
}
|
9723
|
+
},
|
9724
|
+
|
9725
|
+
removeRecordFromOwn: function(record) {
|
9726
|
+
this.members["delete"](record);
|
9727
|
+
this.notifyRecordRelationshipRemoved(record);
|
9728
|
+
this.record.updateRecordArrays();
|
9729
|
+
},
|
9730
|
+
|
9396
9731
|
updateLink: function(link) {
|
9397
9732
|
if (link !== this.link) {
|
9398
9733
|
this.link = link;
|
9399
|
-
this.
|
9734
|
+
this.linkPromise = null;
|
9400
9735
|
this.record.notifyPropertyChange(this.key);
|
9401
9736
|
}
|
9402
9737
|
},
|
9403
9738
|
|
9739
|
+
findLink: function() {
|
9740
|
+
if (this.linkPromise) {
|
9741
|
+
return this.linkPromise;
|
9742
|
+
} else {
|
9743
|
+
var promise = this.fetchLink();
|
9744
|
+
this.linkPromise = promise;
|
9745
|
+
return promise.then(function(result) {
|
9746
|
+
return result;
|
9747
|
+
});
|
9748
|
+
}
|
9749
|
+
},
|
9750
|
+
|
9404
9751
|
updateRecordsFromAdapter: function(records) {
|
9405
9752
|
//TODO Once we have adapter support, we need to handle updated and canonical changes
|
9406
9753
|
this.computeChanges(records);
|
9407
|
-
}
|
9754
|
+
},
|
9755
|
+
|
9756
|
+
notifyRecordRelationshipAdded: Ember.K,
|
9757
|
+
notifyRecordRelationshipRemoved: Ember.K
|
9408
9758
|
};
|
9409
9759
|
|
9410
9760
|
var ManyRelationship = function(store, record, inverseKey, relationshipMeta) {
|
@@ -9432,49 +9782,84 @@ define("ember-data/system/relationships/relationship",
|
|
9432
9782
|
this.record.notifyHasManyRemoved(this.key, record);
|
9433
9783
|
};
|
9434
9784
|
|
9785
|
+
ManyRelationship.prototype.reload = function() {
|
9786
|
+
var self = this;
|
9787
|
+
if (this.link) {
|
9788
|
+
return this.fetchLink();
|
9789
|
+
} else {
|
9790
|
+
return this.store.scheduleFetchMany(this.manyArray.toArray()).then(function() {
|
9791
|
+
//Goes away after the manyArray refactor
|
9792
|
+
self.manyArray.set('isLoaded', true);
|
9793
|
+
return self.manyArray;
|
9794
|
+
});
|
9795
|
+
}
|
9796
|
+
};
|
9797
|
+
|
9435
9798
|
ManyRelationship.prototype.computeChanges = function(records) {
|
9436
9799
|
var members = this.members;
|
9800
|
+
var recordsToRemove = [];
|
9801
|
+
var length;
|
9802
|
+
var record;
|
9803
|
+
var i;
|
9437
9804
|
|
9438
9805
|
records = setForArray(records);
|
9439
9806
|
|
9440
9807
|
members.forEach(function(member) {
|
9441
9808
|
if (records.has(member)) return;
|
9442
9809
|
|
9443
|
-
|
9444
|
-
}
|
9810
|
+
recordsToRemove.push(member);
|
9811
|
+
});
|
9812
|
+
this.removeRecords(recordsToRemove);
|
9445
9813
|
|
9446
9814
|
var hasManyArray = this.manyArray;
|
9447
9815
|
|
9448
|
-
records.
|
9816
|
+
// Using records.toArray() since currently using
|
9817
|
+
// removeRecord can modify length, messing stuff up
|
9818
|
+
// forEach since it directly looks at "length" each
|
9819
|
+
// iteration
|
9820
|
+
records = records.toArray();
|
9821
|
+
length = records.length;
|
9822
|
+
for (i = 0; i < length; i++){
|
9823
|
+
record = records[i];
|
9449
9824
|
//Need to preserve the order of incoming records
|
9450
|
-
if (hasManyArray.objectAt(
|
9451
|
-
|
9825
|
+
if (hasManyArray.objectAt(i) === record ) {
|
9826
|
+
continue;
|
9827
|
+
}
|
9452
9828
|
this.removeRecord(record);
|
9453
|
-
this.addRecord(record,
|
9454
|
-
}
|
9829
|
+
this.addRecord(record, i);
|
9830
|
+
}
|
9455
9831
|
};
|
9456
9832
|
|
9833
|
+
ManyRelationship.prototype.fetchLink = function() {
|
9834
|
+
var self = this;
|
9835
|
+
return this.store.findHasMany(this.record, this.link, this.relationshipMeta).then(function(records){
|
9836
|
+
self.updateRecordsFromAdapter(records);
|
9837
|
+
return self.manyArray;
|
9838
|
+
});
|
9839
|
+
};
|
9840
|
+
|
9841
|
+
ManyRelationship.prototype.findRecords = function() {
|
9842
|
+
var manyArray = this.manyArray;
|
9843
|
+
return this.store.findMany(manyArray.toArray()).then(function(){
|
9844
|
+
//Goes away after the manyArray refactor
|
9845
|
+
manyArray.set('isLoaded', true);
|
9846
|
+
return manyArray;
|
9847
|
+
});
|
9848
|
+
};
|
9457
9849
|
|
9458
9850
|
ManyRelationship.prototype.getRecords = function() {
|
9459
9851
|
if (this.isAsync) {
|
9460
9852
|
var self = this;
|
9461
9853
|
var promise;
|
9462
|
-
if (this.link
|
9463
|
-
promise = this.
|
9464
|
-
self.
|
9465
|
-
self.hasFetchedLink = true;
|
9466
|
-
//TODO(Igor) try to abstract the isLoaded part
|
9467
|
-
self.manyArray.set('isLoaded', true);
|
9468
|
-
return self.manyArray;
|
9854
|
+
if (this.link) {
|
9855
|
+
promise = this.findLink().then(function() {
|
9856
|
+
return self.findRecords();
|
9469
9857
|
});
|
9470
9858
|
} else {
|
9471
|
-
|
9472
|
-
promise = this.store.findMany(manyArray.toArray()).then(function(){
|
9473
|
-
self.manyArray.set('isLoaded', true);
|
9474
|
-
return manyArray;
|
9475
|
-
});
|
9859
|
+
promise = this.findRecords();
|
9476
9860
|
}
|
9477
|
-
return
|
9861
|
+
return PromiseManyArray.create({
|
9862
|
+
content: this.manyArray,
|
9478
9863
|
promise: promise
|
9479
9864
|
});
|
9480
9865
|
} else {
|
@@ -9486,10 +9871,8 @@ define("ember-data/system/relationships/relationship",
|
|
9486
9871
|
|
9487
9872
|
var BelongsToRelationship = function(store, record, inverseKey, relationshipMeta) {
|
9488
9873
|
this._super$constructor(store, record, inverseKey, relationshipMeta);
|
9489
|
-
this.members.add(record);
|
9490
9874
|
this.record = record;
|
9491
9875
|
this.key = relationshipMeta.key;
|
9492
|
-
this.inverseKey = inverseKey;
|
9493
9876
|
this.inverseRecord = null;
|
9494
9877
|
};
|
9495
9878
|
|
@@ -9510,7 +9893,7 @@ define("ember-data/system/relationships/relationship",
|
|
9510
9893
|
if (this.members.has(newRecord)){ return;}
|
9511
9894
|
var type = this.relationshipMeta.type;
|
9512
9895
|
|
9513
|
-
if (this.inverseRecord
|
9896
|
+
if (this.inverseRecord) {
|
9514
9897
|
this.removeRecord(this.inverseRecord);
|
9515
9898
|
}
|
9516
9899
|
|
@@ -9518,6 +9901,11 @@ define("ember-data/system/relationships/relationship",
|
|
9518
9901
|
this._super$addRecord(newRecord);
|
9519
9902
|
};
|
9520
9903
|
|
9904
|
+
BelongsToRelationship.prototype.setRecordPromise = function(newPromise) {
|
9905
|
+
var content = newPromise.get && newPromise.get('content');
|
9906
|
+
this.setRecord(content);
|
9907
|
+
};
|
9908
|
+
|
9521
9909
|
BelongsToRelationship.prototype.notifyRecordRelationshipAdded = function(newRecord) {
|
9522
9910
|
this.record.notifyBelongsToAdded(this.key, this);
|
9523
9911
|
};
|
@@ -9526,36 +9914,44 @@ define("ember-data/system/relationships/relationship",
|
|
9526
9914
|
this.record.notifyBelongsToRemoved(this.key, this);
|
9527
9915
|
};
|
9528
9916
|
|
9529
|
-
BelongsToRelationship.prototype._super$
|
9530
|
-
BelongsToRelationship.prototype.
|
9917
|
+
BelongsToRelationship.prototype._super$removeRecordFromOwn = Relationship.prototype.removeRecordFromOwn;
|
9918
|
+
BelongsToRelationship.prototype.removeRecordFromOwn = function(record) {
|
9531
9919
|
if (!this.members.has(record)){ return;}
|
9532
|
-
this._super$
|
9920
|
+
this._super$removeRecordFromOwn(record);
|
9533
9921
|
this.inverseRecord = null;
|
9534
9922
|
};
|
9535
9923
|
|
9536
|
-
BelongsToRelationship.prototype.
|
9537
|
-
|
9924
|
+
BelongsToRelationship.prototype.findRecord = function() {
|
9925
|
+
if (this.inverseRecord) {
|
9926
|
+
return this.store._findByRecord(this.inverseRecord);
|
9927
|
+
} else {
|
9928
|
+
return Ember.RSVP.Promise.resolve(null);
|
9929
|
+
}
|
9930
|
+
};
|
9931
|
+
|
9932
|
+
BelongsToRelationship.prototype.fetchLink = function() {
|
9933
|
+
var self = this;
|
9934
|
+
return this.store.findBelongsTo(this.record, this.link, this.relationshipMeta).then(function(record){
|
9935
|
+
self.addRecord(record);
|
9936
|
+
return record;
|
9937
|
+
});
|
9538
9938
|
};
|
9539
9939
|
|
9540
9940
|
BelongsToRelationship.prototype.getRecord = function() {
|
9541
9941
|
if (this.isAsync) {
|
9542
9942
|
var promise;
|
9543
|
-
|
9544
|
-
if (this.link && !this.hasFetchedLink){
|
9943
|
+
if (this.link){
|
9545
9944
|
var self = this;
|
9546
|
-
promise = this.
|
9547
|
-
self.
|
9548
|
-
self.hasFetchedLink = true;
|
9549
|
-
return record;
|
9945
|
+
promise = this.findLink().then(function() {
|
9946
|
+
return self.findRecord();
|
9550
9947
|
});
|
9551
|
-
} else if (this.inverseRecord) {
|
9552
|
-
promise = this.store._findByRecord(this.inverseRecord);
|
9553
9948
|
} else {
|
9554
|
-
promise =
|
9949
|
+
promise = this.findRecord();
|
9555
9950
|
}
|
9556
9951
|
|
9557
9952
|
return PromiseObject.create({
|
9558
|
-
promise: promise
|
9953
|
+
promise: promise,
|
9954
|
+
content: this.inverseRecord
|
9559
9955
|
});
|
9560
9956
|
} else {
|
9561
9957
|
return this.inverseRecord;
|
@@ -9563,7 +9959,7 @@ define("ember-data/system/relationships/relationship",
|
|
9563
9959
|
};
|
9564
9960
|
|
9565
9961
|
function setForArray(array) {
|
9566
|
-
var set = new
|
9962
|
+
var set = new OrderedSet();
|
9567
9963
|
|
9568
9964
|
if (array) {
|
9569
9965
|
for (var i=0, l=array.length; i<l; i++) {
|
@@ -9597,8 +9993,8 @@ define("ember-data/system/relationships/relationship",
|
|
9597
9993
|
__exports__.createRelationshipFor = createRelationshipFor;
|
9598
9994
|
});
|
9599
9995
|
define("ember-data/system/store",
|
9600
|
-
["ember-data/system/adapter","ember-inflector/system/string","ember-data/system/promise_proxies","exports"],
|
9601
|
-
function(__dependency1__, __dependency2__, __dependency3__, __exports__) {
|
9996
|
+
["ember-data/system/adapter","ember-inflector/system/string","ember-data/system/map","ember-data/system/promise_proxies","exports"],
|
9997
|
+
function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) {
|
9602
9998
|
"use strict";
|
9603
9999
|
/*globals Ember*/
|
9604
10000
|
/*jshint eqnull:true*/
|
@@ -9610,9 +10006,10 @@ define("ember-data/system/store",
|
|
9610
10006
|
var InvalidError = __dependency1__.InvalidError;
|
9611
10007
|
var Adapter = __dependency1__.Adapter;
|
9612
10008
|
var singularize = __dependency2__.singularize;
|
10009
|
+
var Map = __dependency3__.Map;
|
9613
10010
|
|
9614
|
-
var promiseArray =
|
9615
|
-
var promiseObject =
|
10011
|
+
var promiseArray = __dependency4__.promiseArray;
|
10012
|
+
var promiseObject = __dependency4__.promiseObject;
|
9616
10013
|
|
9617
10014
|
|
9618
10015
|
var get = Ember.get;
|
@@ -9747,7 +10144,7 @@ define("ember-data/system/store",
|
|
9747
10144
|
});
|
9748
10145
|
this._pendingSave = [];
|
9749
10146
|
//Used to keep track of all the find requests that need to be coalesced
|
9750
|
-
this._pendingFetch =
|
10147
|
+
this._pendingFetch = Map.create();
|
9751
10148
|
},
|
9752
10149
|
|
9753
10150
|
/**
|
@@ -10130,10 +10527,10 @@ define("ember-data/system/store",
|
|
10130
10527
|
}
|
10131
10528
|
|
10132
10529
|
this._pendingFetch.forEach(this._flushPendingFetchForType, this);
|
10133
|
-
this._pendingFetch =
|
10530
|
+
this._pendingFetch = Map.create();
|
10134
10531
|
},
|
10135
10532
|
|
10136
|
-
_flushPendingFetchForType: function (
|
10533
|
+
_flushPendingFetchForType: function (recordResolverPairs, type) {
|
10137
10534
|
var store = this;
|
10138
10535
|
var adapter = store.adapterFor(type);
|
10139
10536
|
var shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests;
|
@@ -10724,7 +11121,7 @@ define("ember-data/system/store",
|
|
10724
11121
|
|
10725
11122
|
@method typeMapFor
|
10726
11123
|
@private
|
10727
|
-
@param type
|
11124
|
+
@param {subclass of DS.Model} type
|
10728
11125
|
@return {Object} typeMap
|
10729
11126
|
*/
|
10730
11127
|
typeMapFor: function(type) {
|
@@ -10785,7 +11182,7 @@ define("ember-data/system/store",
|
|
10785
11182
|
var factory;
|
10786
11183
|
|
10787
11184
|
if (typeof key === 'string') {
|
10788
|
-
factory = this.
|
11185
|
+
factory = this.modelFactoryFor(key);
|
10789
11186
|
if (!factory) {
|
10790
11187
|
throw new Ember.Error("No model was found for '" + key + "'");
|
10791
11188
|
}
|
@@ -10802,6 +11199,10 @@ define("ember-data/system/store",
|
|
10802
11199
|
return factory;
|
10803
11200
|
},
|
10804
11201
|
|
11202
|
+
modelFactoryFor: function(key){
|
11203
|
+
return this.container.lookupFactory('model:' + key);
|
11204
|
+
},
|
11205
|
+
|
10805
11206
|
/**
|
10806
11207
|
Push some data for a given type into the store.
|
10807
11208
|
|
@@ -10963,7 +11364,7 @@ define("ember-data/system/store",
|
|
10963
11364
|
```
|
10964
11365
|
|
10965
11366
|
@method normalize
|
10966
|
-
@param {String} The name of the model type for this payload
|
11367
|
+
@param {String} type The name of the model type for this payload
|
10967
11368
|
@param {Object} payload
|
10968
11369
|
@return {Object} The normalized payload
|
10969
11370
|
*/
|
@@ -11533,8 +11934,8 @@ define("ember-data/transforms/base",
|
|
11533
11934
|
```
|
11534
11935
|
|
11535
11936
|
@method serialize
|
11536
|
-
@param deserialized The deserialized value
|
11537
|
-
@return The serialized value
|
11937
|
+
@param {mixed} deserialized The deserialized value
|
11938
|
+
@return {mixed} The serialized value
|
11538
11939
|
*/
|
11539
11940
|
serialize: Ember.required(),
|
11540
11941
|
|
@@ -11551,8 +11952,8 @@ define("ember-data/transforms/base",
|
|
11551
11952
|
```
|
11552
11953
|
|
11553
11954
|
@method deserialize
|
11554
|
-
@param serialized The serialized value
|
11555
|
-
@return The deserialized value
|
11955
|
+
@param {mixed} serialized The serialized value
|
11956
|
+
@return {mixed} The deserialized value
|
11556
11957
|
*/
|
11557
11958
|
deserialize: Ember.required()
|
11558
11959
|
});
|