ember-data-source 2.6.2 → 2.7.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dist/globals/ember-data.js +1033 -868
- data/dist/globals/ember-data.min.js +5 -5
- data/dist/globals/ember-data.prod.js +1002 -853
- data/package.json +4 -4
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33dec8fb2ecc2b2dca716443d07526b12b9b3cdf
|
4
|
+
data.tar.gz: 71f8117dc0fc6993d1ee95c4c6875743b0bec930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6fb1b062982315f424e3a3edb20d9bd41621e22eaf547c9f618d8a274af60caf224cd8e37bc38e2d25f4205975271f913ebb33b415c8b43925fecba48fea33a
|
7
|
+
data.tar.gz: 161aa97282f1e6ca50c67a03caa04684d2943a477cecce815520beb5724fee64509f231e9eff2eb532ec07ed59f19a0cc7282f6120882e1ac8bda5c26f6ea5c6
|
data/dist/globals/ember-data.js
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
* @copyright Copyright 2011-2016 Tilde Inc. and contributors.
|
7
7
|
* Portions Copyright 2011 LivingSocial Inc.
|
8
8
|
* @license Licensed under MIT license (see license.js)
|
9
|
-
* @version 2.
|
9
|
+
* @version 2.7.0-beta.1
|
10
10
|
*/
|
11
11
|
|
12
12
|
var loader, define, requireModule, require, requirejs;
|
@@ -25,14 +25,7 @@ var loader, define, requireModule, require, requirejs;
|
|
25
25
|
|
26
26
|
requirejs = require = requireModule = function(name) {
|
27
27
|
stats.require++;
|
28
|
-
|
29
|
-
var mod = findModule(name, '(require)', pending);
|
30
|
-
|
31
|
-
for (var i = pending.length - 1; i >= 0; i--) {
|
32
|
-
pending[i].exports();
|
33
|
-
}
|
34
|
-
|
35
|
-
return mod.module.exports;
|
28
|
+
return findModule(name, '(require)').module.exports;
|
36
29
|
};
|
37
30
|
|
38
31
|
function resetStats() {
|
@@ -40,19 +33,18 @@ var loader, define, requireModule, require, requirejs;
|
|
40
33
|
define: 0,
|
41
34
|
require: 0,
|
42
35
|
reify: 0,
|
43
|
-
|
36
|
+
build: 0,
|
44
37
|
modules: 0,
|
45
38
|
exports: 0,
|
39
|
+
ensureBuild: 0,
|
46
40
|
resolve: 0,
|
47
41
|
resolveRelative: 0,
|
48
42
|
findModule: 0,
|
49
|
-
pendingQueueLength: 0
|
50
43
|
};
|
51
44
|
requirejs._stats = stats;
|
52
45
|
}
|
53
46
|
|
54
47
|
var stats;
|
55
|
-
|
56
48
|
resetStats();
|
57
49
|
|
58
50
|
loader = {
|
@@ -83,6 +75,8 @@ var loader, define, requireModule, require, requirejs;
|
|
83
75
|
|
84
76
|
var registry = {};
|
85
77
|
var seen = {};
|
78
|
+
var FAILED = false;
|
79
|
+
var LOADED = true;
|
86
80
|
|
87
81
|
var uuid = 0;
|
88
82
|
|
@@ -94,18 +88,17 @@ var loader, define, requireModule, require, requirejs;
|
|
94
88
|
var defaultDeps = ['require', 'exports', 'module'];
|
95
89
|
|
96
90
|
function Module(name, deps, callback, alias) {
|
97
|
-
stats.modules++;
|
91
|
+
stats.modules ++;
|
98
92
|
this.id = uuid++;
|
99
93
|
this.name = name;
|
100
94
|
this.deps = !deps.length && callback.length ? defaultDeps : deps;
|
101
95
|
this.module = { exports: {} };
|
102
96
|
this.callback = callback;
|
97
|
+
this.state = undefined;
|
103
98
|
this.finalized = false;
|
104
99
|
this.hasExportsAsDep = false;
|
105
100
|
this.isAlias = alias;
|
106
101
|
this.reified = new Array(deps.length);
|
107
|
-
this._foundDeps = false;
|
108
|
-
this.isPending = false;
|
109
102
|
}
|
110
103
|
|
111
104
|
Module.prototype.makeDefaultExport = function() {
|
@@ -118,66 +111,46 @@ var loader, define, requireModule, require, requirejs;
|
|
118
111
|
};
|
119
112
|
|
120
113
|
Module.prototype.exports = function() {
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
if (!(this.hasExportsAsDep && result === undefined)) {
|
136
|
-
this.module.exports = result;
|
114
|
+
stats.exports ++;
|
115
|
+
if (this.finalized) {
|
116
|
+
return this.module.exports;
|
117
|
+
} else {
|
118
|
+
if (loader.wrapModules) {
|
119
|
+
this.callback = loader.wrapModules(this.name, this.callback);
|
120
|
+
}
|
121
|
+
var result = this.callback.apply(this, this.reified);
|
122
|
+
if (!(this.hasExportsAsDep && result === undefined)) {
|
123
|
+
this.module.exports = result;
|
124
|
+
}
|
125
|
+
this.makeDefaultExport();
|
126
|
+
this.finalized = true;
|
127
|
+
return this.module.exports;
|
137
128
|
}
|
138
|
-
this.makeDefaultExport();
|
139
|
-
return this.module.exports;
|
140
129
|
};
|
141
130
|
|
142
131
|
Module.prototype.unsee = function() {
|
143
132
|
this.finalized = false;
|
144
|
-
this.
|
145
|
-
this.isPending = false;
|
133
|
+
this.state = undefined;
|
146
134
|
this.module = { exports: {}};
|
147
135
|
};
|
148
136
|
|
149
137
|
Module.prototype.reify = function() {
|
150
138
|
stats.reify++;
|
151
|
-
var reified = this.reified;
|
152
|
-
for (var i = 0; i < reified.length; i++) {
|
153
|
-
var mod = reified[i];
|
154
|
-
reified[i] = mod.exports ? mod.exports : mod.module.exports();
|
155
|
-
}
|
156
|
-
};
|
157
|
-
|
158
|
-
Module.prototype.findDeps = function(pending) {
|
159
|
-
if (this._foundDeps) {
|
160
|
-
return;
|
161
|
-
}
|
162
|
-
|
163
|
-
stats.findDeps++;
|
164
|
-
this._foundDeps = true;
|
165
|
-
this.isPending = true;
|
166
|
-
|
167
139
|
var deps = this.deps;
|
140
|
+
var dep;
|
141
|
+
var reified = this.reified;
|
168
142
|
|
169
143
|
for (var i = 0; i < deps.length; i++) {
|
170
|
-
|
171
|
-
var entry = this.reified[i] = { exports: undefined, module: undefined };
|
144
|
+
dep = deps[i];
|
172
145
|
if (dep === 'exports') {
|
173
146
|
this.hasExportsAsDep = true;
|
174
|
-
|
147
|
+
reified[i] = this.module.exports;
|
175
148
|
} else if (dep === 'require') {
|
176
|
-
|
149
|
+
reified[i] = this.makeRequire();
|
177
150
|
} else if (dep === 'module') {
|
178
|
-
|
151
|
+
reified[i] = this.module;
|
179
152
|
} else {
|
180
|
-
|
153
|
+
reified[i] = findModule(resolve(dep, this.name), this.name).module.exports;
|
181
154
|
}
|
182
155
|
}
|
183
156
|
};
|
@@ -194,6 +167,16 @@ var loader, define, requireModule, require, requirejs;
|
|
194
167
|
return r;
|
195
168
|
};
|
196
169
|
|
170
|
+
Module.prototype.build = function() {
|
171
|
+
stats.ensureBuild++;
|
172
|
+
if (this.state === FAILED || this.state === LOADED) { return; }
|
173
|
+
stats.build++;
|
174
|
+
this.state = FAILED;
|
175
|
+
this.reify()
|
176
|
+
this.exports();
|
177
|
+
this.state = LOADED;
|
178
|
+
};
|
179
|
+
|
197
180
|
define = function(name, deps, callback) {
|
198
181
|
stats.define++;
|
199
182
|
if (arguments.length < 2) {
|
@@ -229,7 +212,7 @@ var loader, define, requireModule, require, requirejs;
|
|
229
212
|
throw new Error('Could not find module `' + name + '` imported from `' + referrer + '`');
|
230
213
|
}
|
231
214
|
|
232
|
-
function findModule(name, referrer
|
215
|
+
function findModule(name, referrer) {
|
233
216
|
stats.findModule++;
|
234
217
|
var mod = registry[name] || registry[name + '/index'];
|
235
218
|
|
@@ -239,11 +222,7 @@ var loader, define, requireModule, require, requirejs;
|
|
239
222
|
|
240
223
|
if (!mod) { missingModule(name, referrer); }
|
241
224
|
|
242
|
-
|
243
|
-
mod.findDeps(pending);
|
244
|
-
pending.push(mod);
|
245
|
-
stats.pendingQueueLength++;
|
246
|
-
}
|
225
|
+
mod.build();
|
247
226
|
return mod;
|
248
227
|
}
|
249
228
|
|
@@ -279,7 +258,7 @@ var loader, define, requireModule, require, requirejs;
|
|
279
258
|
requirejs.entries = requirejs._eak_seen = registry;
|
280
259
|
requirejs.has = has;
|
281
260
|
requirejs.unsee = function(moduleName) {
|
282
|
-
findModule(moduleName, '(unsee)'
|
261
|
+
findModule(moduleName, '(unsee)').unsee();
|
283
262
|
};
|
284
263
|
|
285
264
|
requirejs.clear = function() {
|
@@ -621,7 +600,8 @@ define('ember-data/-private/core', ['exports', 'ember', 'ember-data/version'], f
|
|
621
600
|
@static
|
622
601
|
*/
|
623
602
|
var DS = _ember.default.Namespace.create({
|
624
|
-
VERSION: _emberDataVersion.default
|
603
|
+
VERSION: _emberDataVersion.default,
|
604
|
+
name: "DS"
|
625
605
|
});
|
626
606
|
|
627
607
|
if (_ember.default.libraries) {
|
@@ -711,30 +691,14 @@ define('ember-data/-private/debug', ['exports', 'ember'], function (exports, _em
|
|
711
691
|
assert(assertionMessage, checkPolymorphic(typeClass, addedRecord));
|
712
692
|
}
|
713
693
|
});
|
714
|
-
define('ember-data/-private/ext/date', ['exports', 'ember'], function (exports, _ember) {
|
694
|
+
define('ember-data/-private/ext/date', ['exports', 'ember', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateDebug) {
|
715
695
|
|
716
|
-
/**
|
717
|
-
Date.parse with progressive enhancement for ISO 8601 <https://github.com/csnover/js-iso8601>
|
718
|
-
|
719
|
-
© 2011 Colin Snover <http://zetafleet.com>
|
720
|
-
|
721
|
-
Released under MIT license.
|
722
|
-
|
723
|
-
@class Date
|
724
|
-
@namespace Ember
|
725
|
-
@static
|
726
|
-
*/
|
727
696
|
_ember.default.Date = _ember.default.Date || {};
|
728
697
|
|
729
698
|
var origParse = Date.parse;
|
730
699
|
var numericKeys = [1, 4, 5, 6, 7, 10, 11];
|
731
700
|
|
732
|
-
|
733
|
-
@method parse
|
734
|
-
@param {Date} date
|
735
|
-
@return {Number} timestamp
|
736
|
-
*/
|
737
|
-
_ember.default.Date.parse = function (date) {
|
701
|
+
var parseDate = function (date) {
|
738
702
|
var timestamp, struct;
|
739
703
|
var minutesOffset = 0;
|
740
704
|
|
@@ -742,7 +706,7 @@ define('ember-data/-private/ext/date', ['exports', 'ember'], function (exports,
|
|
742
706
|
// before falling back to any implementation-specific date parsing, so that’s what we do, even if native
|
743
707
|
// implementations could be faster
|
744
708
|
// 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm
|
745
|
-
if (struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(
|
709
|
+
if (struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?:(\d{2}))?)?)?$/.exec(date)) {
|
746
710
|
// avoid NaN timestamps caused by “undefined” values being passed to Date.UTC
|
747
711
|
for (var i = 0, k; k = numericKeys[i]; ++i) {
|
748
712
|
struct[k] = +struct[k] || 0;
|
@@ -768,8 +732,23 @@ define('ember-data/-private/ext/date', ['exports', 'ember'], function (exports,
|
|
768
732
|
return timestamp;
|
769
733
|
};
|
770
734
|
|
735
|
+
exports.parseDate = parseDate;
|
736
|
+
_ember.default.Date.parse = function (date) {
|
737
|
+
// throw deprecation
|
738
|
+
(0, _emberDataPrivateDebug.deprecate)('Ember.Date.parse is deprecated because Safari 5-, IE8-, and\n Firefox 3.6- are no longer supported (see\n https://github.com/csnover/js-iso8601 for the history of this issue).\n Please use Date.parse instead', false, {
|
739
|
+
id: 'ds.ember.date.parse-deprecate',
|
740
|
+
until: '3.0.0'
|
741
|
+
});
|
742
|
+
|
743
|
+
return parseDate(date);
|
744
|
+
};
|
745
|
+
|
771
746
|
if (_ember.default.EXTEND_PROTOTYPES === true || _ember.default.EXTEND_PROTOTYPES.Date) {
|
772
|
-
Date.parse
|
747
|
+
(0, _emberDataPrivateDebug.deprecate)('Overriding Date.parse with Ember.Date.parse is deprecated. Please set ENV.EmberENV.EXTEND_PROTOTYPES.Date to false in config/environment.js\n\n\n// config/environment.js\nENV = {\n EmberENV: {\n EXTEND_PROTOTYPES: {\n Date: false,\n }\n }\n}\n', false, {
|
748
|
+
id: 'ds.date.parse-deprecate',
|
749
|
+
until: '3.0.0'
|
750
|
+
});
|
751
|
+
Date.parse = parseDate;
|
773
752
|
}
|
774
753
|
});
|
775
754
|
/**
|
@@ -784,6 +763,25 @@ define('ember-data/-private/features', ['exports', 'ember'], function (exports,
|
|
784
763
|
return (_Ember$FEATURES = _ember.default.FEATURES).isEnabled.apply(_Ember$FEATURES, arguments);
|
785
764
|
}
|
786
765
|
});
|
766
|
+
define('ember-data/-private/global', ['exports'], function (exports) {
|
767
|
+
/* globals global, window, self */
|
768
|
+
|
769
|
+
// originally from https://github.com/emberjs/ember.js/blob/c0bd26639f50efd6a03ee5b87035fd200e313b8e/packages/ember-environment/lib/global.js
|
770
|
+
|
771
|
+
// from lodash to catch fake globals
|
772
|
+
function checkGlobal(value) {
|
773
|
+
return value && value.Object === Object ? value : undefined;
|
774
|
+
}
|
775
|
+
|
776
|
+
// element ids can ruin global miss checks
|
777
|
+
function checkElementIdShadowing(value) {
|
778
|
+
return value && value.nodeType === undefined ? value : undefined;
|
779
|
+
}
|
780
|
+
|
781
|
+
// export real global
|
782
|
+
exports.default = checkGlobal(checkElementIdShadowing(typeof global === 'object' && global)) || checkGlobal(typeof self === 'object' && self) || checkGlobal(typeof window === 'object' && window) || new Function('return this')();
|
783
|
+
// eval outside of strict mode
|
784
|
+
});
|
787
785
|
define("ember-data/-private/initializers/data-adapter", ["exports", "ember-data/-private/system/debug/debug-adapter"], function (exports, _emberDataPrivateSystemDebugDebugAdapter) {
|
788
786
|
exports.default = initializeDebugAdapter;
|
789
787
|
|
@@ -921,7 +919,7 @@ define('ember-data/-private/system/coerce-id', ['exports'], function (exports) {
|
|
921
919
|
// corresponding record, we will not know if it is a string or a number.
|
922
920
|
|
923
921
|
function coerceId(id) {
|
924
|
-
return id
|
922
|
+
return id === null || id === undefined || id === '' ? null : id + '';
|
925
923
|
}
|
926
924
|
});
|
927
925
|
define('ember-data/-private/system/container-proxy', ['exports', 'ember-data/-private/debug'], function (exports, _emberDataPrivateDebug) {
|
@@ -2125,7 +2123,7 @@ define('ember-data/-private/system/model/errors', ['exports', 'ember', 'ember-da
|
|
2125
2123
|
}
|
2126
2124
|
});
|
2127
2125
|
});
|
2128
|
-
define("ember-data/-private/system/model/internal-model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/model/states", "ember-data/-private/system/relationships/state/create", "ember-data/-private/system/snapshot", "ember-data/-private/system/empty-object", "ember-data/-private/
|
2126
|
+
define("ember-data/-private/system/model/internal-model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/model/states", "ember-data/-private/system/relationships/state/create", "ember-data/-private/system/snapshot", "ember-data/-private/system/empty-object", "ember-data/-private/utils", "ember-data/-private/system/references"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemModelStates, _emberDataPrivateSystemRelationshipsStateCreate, _emberDataPrivateSystemSnapshot, _emberDataPrivateSystemEmptyObject, _emberDataPrivateUtils, _emberDataPrivateSystemReferences) {
|
2129
2127
|
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })();
|
2130
2128
|
|
2131
2129
|
exports.default = InternalModel;
|
@@ -2937,12 +2935,9 @@ define("ember-data/-private/system/model/internal-model", ["exports", "ember", "
|
|
2937
2935
|
} else {
|
2938
2936
|
return "<" + this.modelName + ":" + this.id + ">";
|
2939
2937
|
}
|
2940
|
-
}
|
2941
|
-
};
|
2942
|
-
|
2943
|
-
if (true) {
|
2938
|
+
},
|
2944
2939
|
|
2945
|
-
|
2940
|
+
referenceFor: function (type, name) {
|
2946
2941
|
var reference = this.references[name];
|
2947
2942
|
|
2948
2943
|
if (!reference) {
|
@@ -2958,10 +2953,10 @@ define("ember-data/-private/system/model/internal-model", ["exports", "ember", "
|
|
2958
2953
|
}
|
2959
2954
|
|
2960
2955
|
return reference;
|
2961
|
-
}
|
2962
|
-
}
|
2956
|
+
}
|
2957
|
+
};
|
2963
2958
|
});
|
2964
|
-
define("ember-data/-private/system/model/model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/model/errors", "ember-data/-private/
|
2959
|
+
define("ember-data/-private/system/model/model", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/model/errors", "ember-data/-private/system/debug/debug-info", "ember-data/-private/system/relationships/belongs-to", "ember-data/-private/system/relationships/has-many", "ember-data/-private/system/relationships/ext", "ember-data/-private/system/model/attr"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemModelErrors, _emberDataPrivateSystemDebugDebugInfo, _emberDataPrivateSystemRelationshipsBelongsTo, _emberDataPrivateSystemRelationshipsHasMany, _emberDataPrivateSystemRelationshipsExt, _emberDataPrivateSystemModelAttr) {
|
2965
2960
|
|
2966
2961
|
/**
|
2967
2962
|
@module ember-data
|
@@ -3434,6 +3429,22 @@ define("ember-data/-private/system/model/model", ["exports", "ember", "ember-dat
|
|
3434
3429
|
}
|
3435
3430
|
}
|
3436
3431
|
});
|
3432
|
+
```
|
3433
|
+
If you pass an object on the `adapterOptions` property of the options
|
3434
|
+
argument it will be passed to you adapter via the snapshot
|
3435
|
+
```js
|
3436
|
+
record.destroyRecord({ adapterOptions: { subscribe: false } });
|
3437
|
+
```
|
3438
|
+
```app/adapters/post.js
|
3439
|
+
import MyCustomAdapter from './custom-adapter';
|
3440
|
+
export default MyCustomAdapter.extend({
|
3441
|
+
deleteRecord: function(store, type, snapshot) {
|
3442
|
+
if (snapshot.adapterOptions.subscribe) {
|
3443
|
+
// ...
|
3444
|
+
}
|
3445
|
+
// ...
|
3446
|
+
}
|
3447
|
+
});
|
3437
3448
|
```
|
3438
3449
|
@method destroyRecord
|
3439
3450
|
@param {Object} options
|
@@ -3565,7 +3576,23 @@ define("ember-data/-private/system/model/model", ["exports", "ember", "ember-dat
|
|
3565
3576
|
// Error callback
|
3566
3577
|
});
|
3567
3578
|
```
|
3568
|
-
|
3579
|
+
If you pass an object on the `adapterOptions` property of the options
|
3580
|
+
argument it will be passed to you adapter via the snapshot
|
3581
|
+
```js
|
3582
|
+
record.save({ adapterOptions: { subscribe: false } });
|
3583
|
+
```
|
3584
|
+
```app/adapters/post.js
|
3585
|
+
import MyCustomAdapter from './custom-adapter';
|
3586
|
+
export default MyCustomAdapter.extend({
|
3587
|
+
updateRecord: function(store, type, snapshot) {
|
3588
|
+
if (snapshot.adapterOptions.subscribe) {
|
3589
|
+
// ...
|
3590
|
+
}
|
3591
|
+
// ...
|
3592
|
+
}
|
3593
|
+
});
|
3594
|
+
```
|
3595
|
+
@method save
|
3569
3596
|
@param {Object} options
|
3570
3597
|
@return {Promise} a promise that will be resolved when the adapter returns
|
3571
3598
|
successfully or rejected if the adapter returns with an error.
|
@@ -3650,12 +3677,103 @@ define("ember-data/-private/system/model/model", ["exports", "ember", "ember-dat
|
|
3650
3677
|
(0, _emberDataPrivateDebug.assert)("The `attr` method is not available on DS.Model, a DS.Snapshot was probably expected. Are you passing a DS.Model instead of a DS.Snapshot to your serializer?", false);
|
3651
3678
|
},
|
3652
3679
|
|
3653
|
-
|
3654
|
-
|
3680
|
+
/**
|
3681
|
+
Get the reference for the specified belongsTo relationship.
|
3682
|
+
Example
|
3683
|
+
```javascript
|
3684
|
+
// models/blog.js
|
3685
|
+
export default DS.Model.extend({
|
3686
|
+
user: DS.belongsTo({ async: true })
|
3687
|
+
});
|
3688
|
+
var blog = store.push({
|
3689
|
+
type: 'blog',
|
3690
|
+
id: 1,
|
3691
|
+
relationships: {
|
3692
|
+
user: { type: 'user', id: 1 }
|
3693
|
+
}
|
3694
|
+
});
|
3695
|
+
var userRef = blog.belongsTo('user');
|
3696
|
+
// check if the user relationship is loaded
|
3697
|
+
var isLoaded = userRef.value() !== null;
|
3698
|
+
// get the record of the reference (null if not yet available)
|
3699
|
+
var user = userRef.value();
|
3700
|
+
// get the identifier of the reference
|
3701
|
+
if (userRef.remoteType() === "id") {
|
3702
|
+
var id = userRef.id();
|
3703
|
+
} else if (userRef.remoteType() === "link") {
|
3704
|
+
var link = userRef.link();
|
3705
|
+
}
|
3706
|
+
// load user (via store.findRecord or store.findBelongsTo)
|
3707
|
+
userRef.load().then(...)
|
3708
|
+
// or trigger a reload
|
3709
|
+
userRef.reload().then(...)
|
3710
|
+
// provide data for reference
|
3711
|
+
userRef.push({
|
3712
|
+
type: 'user',
|
3713
|
+
id: 1,
|
3714
|
+
attributes: {
|
3715
|
+
username: "@user"
|
3716
|
+
}
|
3717
|
+
}).then(function(user) {
|
3718
|
+
userRef.value() === user;
|
3719
|
+
});
|
3720
|
+
```
|
3721
|
+
@method belongsTo
|
3722
|
+
@param {String} name of the relationship
|
3723
|
+
@since 2.5.0
|
3724
|
+
@return {BelongsToReference} reference for this relationship
|
3725
|
+
*/
|
3726
|
+
belongsTo: function (name) {
|
3727
|
+
return this._internalModel.referenceFor('belongsTo', name);
|
3655
3728
|
},
|
3656
3729
|
|
3657
|
-
|
3658
|
-
|
3730
|
+
/**
|
3731
|
+
Get the reference for the specified hasMany relationship.
|
3732
|
+
Example
|
3733
|
+
```javascript
|
3734
|
+
// models/blog.js
|
3735
|
+
export default DS.Model.extend({
|
3736
|
+
comments: DS.hasMany({ async: true })
|
3737
|
+
});
|
3738
|
+
var blog = store.push({
|
3739
|
+
type: 'blog',
|
3740
|
+
id: 1,
|
3741
|
+
relationships: {
|
3742
|
+
comments: {
|
3743
|
+
data: [
|
3744
|
+
{ type: 'comment', id: 1 },
|
3745
|
+
{ type: 'comment', id: 2 }
|
3746
|
+
]
|
3747
|
+
}
|
3748
|
+
}
|
3749
|
+
});
|
3750
|
+
var commentsRef = blog.hasMany('comments');
|
3751
|
+
// check if the comments are loaded already
|
3752
|
+
var isLoaded = commentsRef.value() !== null;
|
3753
|
+
// get the records of the reference (null if not yet available)
|
3754
|
+
var comments = commentsRef.value();
|
3755
|
+
// get the identifier of the reference
|
3756
|
+
if (commentsRef.remoteType() === "ids") {
|
3757
|
+
var ids = commentsRef.ids();
|
3758
|
+
} else if (commentsRef.remoteType() === "link") {
|
3759
|
+
var link = commentsRef.link();
|
3760
|
+
}
|
3761
|
+
// load comments (via store.findMany or store.findHasMany)
|
3762
|
+
commentsRef.load().then(...)
|
3763
|
+
// or trigger a reload
|
3764
|
+
commentsRef.reload().then(...)
|
3765
|
+
// provide data for reference
|
3766
|
+
commentsRef.push([{ type: 'comment', id: 1 }, { type: 'comment', id: 2 }]).then(function(comments) {
|
3767
|
+
commentsRef.value() === comments;
|
3768
|
+
});
|
3769
|
+
```
|
3770
|
+
@method hasMany
|
3771
|
+
@param {String} name of the relationship
|
3772
|
+
@since 2.5.0
|
3773
|
+
@return {HasManyReference} reference for this relationship
|
3774
|
+
*/
|
3775
|
+
hasMany: function (name) {
|
3776
|
+
return this._internalModel.referenceFor('hasMany', name);
|
3659
3777
|
},
|
3660
3778
|
|
3661
3779
|
setId: _ember.default.observer('id', function () {
|
@@ -3730,109 +3848,6 @@ define("ember-data/-private/system/model/model", ["exports", "ember", "ember-dat
|
|
3730
3848
|
});
|
3731
3849
|
}
|
3732
3850
|
|
3733
|
-
if (true) {
|
3734
|
-
|
3735
|
-
Model.reopen({
|
3736
|
-
|
3737
|
-
/**
|
3738
|
-
Get the reference for the specified belongsTo relationship.
|
3739
|
-
Example
|
3740
|
-
```javascript
|
3741
|
-
// models/blog.js
|
3742
|
-
export default DS.Model.extend({
|
3743
|
-
user: DS.belongsTo({ async: true })
|
3744
|
-
});
|
3745
|
-
var blog = store.push({
|
3746
|
-
type: 'blog',
|
3747
|
-
id: 1,
|
3748
|
-
relationships: {
|
3749
|
-
user: { type: 'user', id: 1 }
|
3750
|
-
}
|
3751
|
-
});
|
3752
|
-
var userRef = blog.belongsTo('user');
|
3753
|
-
// check if the user relationship is loaded
|
3754
|
-
var isLoaded = userRef.value() !== null;
|
3755
|
-
// get the record of the reference (null if not yet available)
|
3756
|
-
var user = userRef.value();
|
3757
|
-
// get the identifier of the reference
|
3758
|
-
if (userRef.remoteType() === "id") {
|
3759
|
-
var id = userRef.id();
|
3760
|
-
} else if (userRef.remoteType() === "link") {
|
3761
|
-
var link = userRef.link();
|
3762
|
-
}
|
3763
|
-
// load user (via store.findRecord or store.findBelongsTo)
|
3764
|
-
userRef.load().then(...)
|
3765
|
-
// or trigger a reload
|
3766
|
-
userRef.reload().then(...)
|
3767
|
-
// provide data for reference
|
3768
|
-
userRef.push({
|
3769
|
-
type: 'user',
|
3770
|
-
id: 1,
|
3771
|
-
attributes: {
|
3772
|
-
username: "@user"
|
3773
|
-
}
|
3774
|
-
}).then(function(user) {
|
3775
|
-
userRef.value() === user;
|
3776
|
-
});
|
3777
|
-
```
|
3778
|
-
@method belongsTo
|
3779
|
-
@param {String} name of the relationship
|
3780
|
-
@return {BelongsToReference} reference for this relationship
|
3781
|
-
*/
|
3782
|
-
belongsTo: function (name) {
|
3783
|
-
return this._internalModel.referenceFor('belongsTo', name);
|
3784
|
-
},
|
3785
|
-
|
3786
|
-
/**
|
3787
|
-
Get the reference for the specified hasMany relationship.
|
3788
|
-
Example
|
3789
|
-
```javascript
|
3790
|
-
// models/blog.js
|
3791
|
-
export default DS.Model.extend({
|
3792
|
-
comments: DS.hasMany({ async: true })
|
3793
|
-
});
|
3794
|
-
var blog = store.push({
|
3795
|
-
type: 'blog',
|
3796
|
-
id: 1,
|
3797
|
-
relationships: {
|
3798
|
-
comments: {
|
3799
|
-
data: [
|
3800
|
-
{ type: 'comment', id: 1 },
|
3801
|
-
{ type: 'comment', id: 2 }
|
3802
|
-
]
|
3803
|
-
}
|
3804
|
-
}
|
3805
|
-
});
|
3806
|
-
var commentsRef = blog.hasMany('comments');
|
3807
|
-
// check if the comments are loaded already
|
3808
|
-
var isLoaded = commentsRef.value() !== null;
|
3809
|
-
// get the records of the reference (null if not yet available)
|
3810
|
-
var comments = commentsRef.value();
|
3811
|
-
// get the identifier of the reference
|
3812
|
-
if (commentsRef.remoteType() === "ids") {
|
3813
|
-
var ids = commentsRef.ids();
|
3814
|
-
} else if (commentsRef.remoteType() === "link") {
|
3815
|
-
var link = commentsRef.link();
|
3816
|
-
}
|
3817
|
-
// load comments (via store.findMany or store.findHasMany)
|
3818
|
-
commentsRef.load().then(...)
|
3819
|
-
// or trigger a reload
|
3820
|
-
commentsRef.reload().then(...)
|
3821
|
-
// provide data for reference
|
3822
|
-
commentsRef.push([{ type: 'comment', id: 1 }, { type: 'comment', id: 2 }]).then(function(comments) {
|
3823
|
-
commentsRef.value() === comments;
|
3824
|
-
});
|
3825
|
-
```
|
3826
|
-
@method hasMany
|
3827
|
-
@param {String} name of the relationship
|
3828
|
-
@return {HasManyReference} reference for this relationship
|
3829
|
-
*/
|
3830
|
-
hasMany: function (name) {
|
3831
|
-
return this._internalModel.referenceFor('hasMany', name);
|
3832
|
-
}
|
3833
|
-
});
|
3834
|
-
}
|
3835
|
-
|
3836
3851
|
Model.reopenClass(_emberDataPrivateSystemRelationshipsExt.RelationshipsClassMethodsMixin);
|
3837
3852
|
Model.reopenClass(_emberDataPrivateSystemModelAttr.AttrClassMethodsMixin);
|
3838
3853
|
|
@@ -4579,7 +4594,6 @@ define('ember-data/-private/system/model/states', ['exports', 'ember', 'ember-da
|
|
4579
4594
|
};
|
4580
4595
|
|
4581
4596
|
function wireState(object, parent, name) {
|
4582
|
-
/*jshint proto:true*/
|
4583
4597
|
// TODO: Use Object.create and copy instead
|
4584
4598
|
object = mixin(parent ? Object.create(parent) : {}, object);
|
4585
4599
|
object.parentState = parent;
|
@@ -4676,7 +4690,7 @@ define('ember-data/-private/system/ordered-set', ['exports', 'ember'], function
|
|
4676
4690
|
|
4677
4691
|
presenceSet[guid] = true;
|
4678
4692
|
|
4679
|
-
if (idx === undefined || idx
|
4693
|
+
if (idx === undefined || idx === null) {
|
4680
4694
|
list.push(obj);
|
4681
4695
|
} else {
|
4682
4696
|
list.splice(idx, 0, obj);
|
@@ -5218,9 +5232,7 @@ define("ember-data/-private/system/record-arrays/adapter-populated-record-array"
|
|
5218
5232
|
meta: (0, _emberDataPrivateSystemCloneNull.default)(payload.meta)
|
5219
5233
|
});
|
5220
5234
|
|
5221
|
-
|
5222
|
-
this.set('links', (0, _emberDataPrivateSystemCloneNull.default)(payload.links));
|
5223
|
-
}
|
5235
|
+
this.set('links', (0, _emberDataPrivateSystemCloneNull.default)(payload.links));
|
5224
5236
|
|
5225
5237
|
internalModels.forEach(function (record) {
|
5226
5238
|
_this.manager.recordArraysForRecord(record).add(_this);
|
@@ -5501,7 +5513,7 @@ define('ember-data/-private/system/references', ['exports', 'ember-data/-private
|
|
5501
5513
|
exports.BelongsToReference = _emberDataPrivateSystemReferencesBelongsTo.default;
|
5502
5514
|
exports.HasManyReference = _emberDataPrivateSystemReferencesHasMany.default;
|
5503
5515
|
});
|
5504
|
-
define('ember-data/-private/system/references/belongs-to', ['exports', 'ember-data/model', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/debug'], function (exports, _emberDataModel, _ember, _emberDataPrivateSystemReferencesReference, _emberDataPrivateDebug) {
|
5516
|
+
define('ember-data/-private/system/references/belongs-to', ['exports', 'ember-data/model', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/features', 'ember-data/-private/debug'], function (exports, _emberDataModel, _ember, _emberDataPrivateSystemReferencesReference, _emberDataPrivateFeatures, _emberDataPrivateDebug) {
|
5505
5517
|
|
5506
5518
|
var BelongsToReference = function (store, parentInternalModel, belongsToRelationship) {
|
5507
5519
|
this._super$constructor(store, parentInternalModel);
|
@@ -5591,7 +5603,7 @@ define('ember-data/-private/system/references/belongs-to', ['exports', 'ember-da
|
|
5591
5603
|
|
5592
5604
|
exports.default = BelongsToReference;
|
5593
5605
|
});
|
5594
|
-
define('ember-data/-private/system/references/has-many', ['exports', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/debug'], function (exports, _ember, _emberDataPrivateSystemReferencesReference, _emberDataPrivateDebug) {
|
5606
|
+
define('ember-data/-private/system/references/has-many', ['exports', 'ember', 'ember-data/-private/system/references/reference', 'ember-data/-private/debug', 'ember-data/-private/features'], function (exports, _ember, _emberDataPrivateSystemReferencesReference, _emberDataPrivateDebug, _emberDataPrivateFeatures) {
|
5595
5607
|
|
5596
5608
|
var get = _ember.default.get;
|
5597
5609
|
|
@@ -5638,20 +5650,38 @@ define('ember-data/-private/system/references/has-many', ['exports', 'ember', 'e
|
|
5638
5650
|
|
5639
5651
|
return _ember.default.RSVP.resolve(objectOrPromise).then(function (payload) {
|
5640
5652
|
var array = payload;
|
5653
|
+
|
5654
|
+
var useLegacyArrayPush = true;
|
5641
5655
|
if (typeof payload === "object" && payload.data) {
|
5642
5656
|
array = payload.data;
|
5657
|
+
useLegacyArrayPush = array.length && array[0].data;
|
5643
5658
|
}
|
5644
5659
|
|
5645
|
-
|
5646
|
-
var record = _this.store.push(obj);
|
5660
|
+
useLegacyArrayPush = true;
|
5647
5661
|
|
5648
|
-
|
5649
|
-
|
5650
|
-
|
5662
|
+
var internalModels = undefined;
|
5663
|
+
if (useLegacyArrayPush) {
|
5664
|
+
internalModels = array.map(function (obj) {
|
5665
|
+
var record = _this.store.push(obj);
|
5666
|
+
|
5667
|
+
(0, _emberDataPrivateDebug.runInDebug)(function () {
|
5668
|
+
var relationshipMeta = _this.hasManyRelationship.relationshipMeta;
|
5669
|
+
(0, _emberDataPrivateDebug.assertPolymorphicType)(_this.internalModel, relationshipMeta, record._internalModel);
|
5670
|
+
});
|
5671
|
+
|
5672
|
+
return record._internalModel;
|
5651
5673
|
});
|
5674
|
+
} else {
|
5675
|
+
var records = _this.store.push(payload);
|
5676
|
+
internalModels = _ember.default.A(records).mapBy('_internalModel');
|
5652
5677
|
|
5653
|
-
|
5654
|
-
|
5678
|
+
(0, _emberDataPrivateDebug.runInDebug)(function () {
|
5679
|
+
internalModels.forEach(function (internalModel) {
|
5680
|
+
var relationshipMeta = _this.hasManyRelationship.relationshipMeta;
|
5681
|
+
(0, _emberDataPrivateDebug.assertPolymorphicType)(_this.internalModel, relationshipMeta, internalModel);
|
5682
|
+
});
|
5683
|
+
});
|
5684
|
+
}
|
5655
5685
|
|
5656
5686
|
_this.hasManyRelationship.computeChanges(internalModels);
|
5657
5687
|
|
@@ -6356,9 +6386,9 @@ define("ember-data/-private/system/relationships/ext", ["exports", "ember", "emb
|
|
6356
6386
|
import Blog from 'app/models/blog';
|
6357
6387
|
var relationshipsByName = Ember.get(Blog, 'relationshipsByName');
|
6358
6388
|
relationshipsByName.get('users');
|
6359
|
-
//=> { key: 'users', kind: 'hasMany', type:
|
6389
|
+
//=> { key: 'users', kind: 'hasMany', type: 'user', options: Object, isRelationship: true }
|
6360
6390
|
relationshipsByName.get('owner');
|
6361
|
-
//=> { key: 'owner', kind: 'belongsTo', type:
|
6391
|
+
//=> { key: 'owner', kind: 'belongsTo', type: 'user', options: Object, isRelationship: true }
|
6362
6392
|
```
|
6363
6393
|
@property relationshipsByName
|
6364
6394
|
@static
|
@@ -6451,14 +6481,14 @@ define("ember-data/-private/system/relationships/ext", ["exports", "ember", "emb
|
|
6451
6481
|
var knownKey = knownSide.key;
|
6452
6482
|
var knownKind = knownSide.kind;
|
6453
6483
|
var inverse = this.inverseFor(knownKey, store);
|
6454
|
-
|
6455
|
-
|
6484
|
+
// let key;
|
6485
|
+
var otherKind = undefined;
|
6456
6486
|
|
6457
6487
|
if (!inverse) {
|
6458
6488
|
return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone';
|
6459
6489
|
}
|
6460
6490
|
|
6461
|
-
key = inverse.name;
|
6491
|
+
// key = inverse.name;
|
6462
6492
|
otherKind = inverse.kind;
|
6463
6493
|
|
6464
6494
|
if (otherKind === 'belongsTo') {
|
@@ -6488,7 +6518,7 @@ define("ember-data/-private/system/relationships/ext", ["exports", "ember", "emb
|
|
6488
6518
|
- **kind** <span class="type">String</span> "hasMany" or "belongsTo"
|
6489
6519
|
- **options** <span class="type">Object</span> the original options hash passed when the relationship was declared
|
6490
6520
|
- **parentType** <span class="type">DS.Model</span> the type of the Model that owns this relationship
|
6491
|
-
- **type** <span class="type">
|
6521
|
+
- **type** <span class="type">String</span> the type name of the related Model
|
6492
6522
|
Note that in addition to a callback, you can also pass an optional target
|
6493
6523
|
object that will be set as `this` on the context.
|
6494
6524
|
Example
|
@@ -7406,8 +7436,11 @@ define("ember-data/-private/system/relationships/state/relationship", ["exports"
|
|
7406
7436
|
}
|
7407
7437
|
};
|
7408
7438
|
});
|
7409
|
-
define('ember-data/-private/system/snapshot-record-array', ['exports'
|
7439
|
+
define('ember-data/-private/system/snapshot-record-array', ['exports'], function (exports) {
|
7410
7440
|
exports.default = SnapshotRecordArray;
|
7441
|
+
/**
|
7442
|
+
@module ember-data
|
7443
|
+
*/
|
7411
7444
|
|
7412
7445
|
/**
|
7413
7446
|
@class SnapshotRecordArray
|
@@ -7460,9 +7493,7 @@ define('ember-data/-private/system/snapshot-record-array', ['exports', 'ember-da
|
|
7460
7493
|
*/
|
7461
7494
|
this.adapterOptions = options.adapterOptions;
|
7462
7495
|
|
7463
|
-
|
7464
|
-
this.include = options.include;
|
7465
|
-
}
|
7496
|
+
this.include = options.include;
|
7466
7497
|
}
|
7467
7498
|
|
7468
7499
|
/**
|
@@ -7480,10 +7511,7 @@ define('ember-data/-private/system/snapshot-record-array', ['exports', 'ember-da
|
|
7480
7511
|
return this._snapshots;
|
7481
7512
|
};
|
7482
7513
|
});
|
7483
|
-
|
7484
|
-
@module ember-data
|
7485
|
-
*/
|
7486
|
-
define('ember-data/-private/system/snapshot', ['exports', 'ember', 'ember-data/-private/system/empty-object', 'ember-data/-private/features'], function (exports, _ember, _emberDataPrivateSystemEmptyObject, _emberDataPrivateFeatures) {
|
7514
|
+
define("ember-data/-private/system/snapshot", ["exports", "ember", "ember-data/-private/system/empty-object"], function (exports, _ember, _emberDataPrivateSystemEmptyObject) {
|
7487
7515
|
exports.default = Snapshot;
|
7488
7516
|
|
7489
7517
|
var get = _ember.default.get;
|
@@ -7525,9 +7553,7 @@ define('ember-data/-private/system/snapshot', ['exports', 'ember', 'ember-data/-
|
|
7525
7553
|
*/
|
7526
7554
|
this.adapterOptions = options.adapterOptions;
|
7527
7555
|
|
7528
|
-
|
7529
|
-
this.include = options.include;
|
7530
|
-
}
|
7556
|
+
this.include = options.include;
|
7531
7557
|
|
7532
7558
|
this._changedAttributes = record.changedAttributes();
|
7533
7559
|
}
|
@@ -7812,7 +7838,7 @@ define('ember-data/-private/system/snapshot', ['exports', 'ember', 'ember-data/-
|
|
7812
7838
|
@module ember-data
|
7813
7839
|
*/
|
7814
7840
|
define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/model', 'ember-data/-private/debug', 'ember-data/-private/system/normalize-link', 'ember-data/-private/system/normalize-model-name', 'ember-data/adapters/errors', 'ember-data/-private/system/promise-proxies', 'ember-data/-private/system/store/common', 'ember-data/-private/system/store/serializer-response', 'ember-data/-private/system/store/serializers', 'ember-data/-private/system/store/finders', 'ember-data/-private/utils', 'ember-data/-private/system/coerce-id', 'ember-data/-private/system/record-array-manager', 'ember-data/-private/system/store/container-instance-cache', 'ember-data/-private/system/model/internal-model', 'ember-data/-private/system/empty-object', 'ember-data/-private/features'], function (exports, _ember, _emberDataModel, _emberDataPrivateDebug, _emberDataPrivateSystemNormalizeLink, _emberDataPrivateSystemNormalizeModelName, _emberDataAdaptersErrors, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemStoreCommon, _emberDataPrivateSystemStoreSerializerResponse, _emberDataPrivateSystemStoreSerializers, _emberDataPrivateSystemStoreFinders, _emberDataPrivateUtils, _emberDataPrivateSystemCoerceId, _emberDataPrivateSystemRecordArrayManager, _emberDataPrivateSystemStoreContainerInstanceCache, _emberDataPrivateSystemModelInternalModel, _emberDataPrivateSystemEmptyObject, _emberDataPrivateFeatures) {
|
7815
|
-
var badIdFormatAssertion = '`id` has to be non-empty string or number';
|
7841
|
+
var badIdFormatAssertion = '`id` passed to `findRecord()` has to be non-empty string or number';
|
7816
7842
|
|
7817
7843
|
exports.badIdFormatAssertion = badIdFormatAssertion;
|
7818
7844
|
var Backburner = _ember.default._Backburner;
|
@@ -8170,6 +8196,7 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8170
8196
|
method to find the necessary data. If the record is already present in the
|
8171
8197
|
store, it depends on the reload behavior _when_ the returned promise
|
8172
8198
|
resolves.
|
8199
|
+
### Reloading
|
8173
8200
|
The reload behavior is configured either via the passed `options` hash or
|
8174
8201
|
the result of the adapter's `shouldReloadRecord`.
|
8175
8202
|
If `{ reload: true }` is passed or `adapter.shouldReloadRecord` evaluates
|
@@ -8197,6 +8224,7 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8197
8224
|
```
|
8198
8225
|
If no reload is indicated via the abovementioned ways, then the promise
|
8199
8226
|
immediately resolves with the cached version in the store.
|
8227
|
+
### Background Reloading
|
8200
8228
|
Optionally, if `adapter.shouldBackgroundReloadRecord` evaluates to `true`,
|
8201
8229
|
then a background reload is started, which updates the records' data, once
|
8202
8230
|
it is available:
|
@@ -8231,6 +8259,40 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8231
8259
|
// }
|
8232
8260
|
// ]
|
8233
8261
|
blogPost.get('revision'); // 2
|
8262
|
+
```
|
8263
|
+
If you would like to force or prevent background reloading, you can set a
|
8264
|
+
boolean value for `backgroundReload` in the options object for
|
8265
|
+
`findRecord`.
|
8266
|
+
```app/routes/post/edit.js
|
8267
|
+
import Ember from 'ember';
|
8268
|
+
export default Ember.Route.extend({
|
8269
|
+
model: function(params) {
|
8270
|
+
return this.store.findRecord('post', params.post_id, { backgroundReload: false });
|
8271
|
+
}
|
8272
|
+
});
|
8273
|
+
```
|
8274
|
+
If you pass an object on the `adapterOptions` property of the options
|
8275
|
+
argument it will be passed to you adapter via the snapshot
|
8276
|
+
```app/routes/post/edit.js
|
8277
|
+
import Ember from 'ember';
|
8278
|
+
export default Ember.Route.extend({
|
8279
|
+
model: function(params) {
|
8280
|
+
return this.store.findRecord('post', params.post_id, {
|
8281
|
+
adapterOptions: { subscribe: false }
|
8282
|
+
});
|
8283
|
+
}
|
8284
|
+
});
|
8285
|
+
```
|
8286
|
+
```app/adapters/post.js
|
8287
|
+
import MyCustomAdapter from './custom-adapter';
|
8288
|
+
export default MyCustomAdapter.extend({
|
8289
|
+
findRecord: function(store, type, id, snapshot) {
|
8290
|
+
if (snapshot.adapterOptions.subscribe) {
|
8291
|
+
// ...
|
8292
|
+
}
|
8293
|
+
// ...
|
8294
|
+
}
|
8295
|
+
});
|
8234
8296
|
```
|
8235
8297
|
See [peekRecord](#method_peekRecord) to get the cached version of a record.
|
8236
8298
|
@method findRecord
|
@@ -8262,16 +8324,21 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8262
8324
|
return this.scheduleFetch(internalModel, options);
|
8263
8325
|
}
|
8264
8326
|
|
8265
|
-
// Refetch the record if the adapter thinks the record is stale
|
8266
8327
|
var snapshot = internalModel.createSnapshot(options);
|
8267
8328
|
var typeClass = internalModel.type;
|
8268
8329
|
var adapter = this.adapterFor(typeClass.modelName);
|
8330
|
+
|
8331
|
+
// Refetch the record if the adapter thinks the record is stale
|
8269
8332
|
if (adapter.shouldReloadRecord(this, snapshot)) {
|
8270
8333
|
return this.scheduleFetch(internalModel, options);
|
8271
8334
|
}
|
8272
8335
|
|
8273
|
-
|
8274
|
-
|
8336
|
+
if (options.backgroundReload === false) {
|
8337
|
+
return Promise.resolve(internalModel);
|
8338
|
+
}
|
8339
|
+
|
8340
|
+
// Trigger the background refetch if backgroundReload option is passed
|
8341
|
+
if (options.backgroundReload || adapter.shouldBackgroundReloadRecord(this, snapshot)) {
|
8275
8342
|
this.scheduleFetch(internalModel, options);
|
8276
8343
|
}
|
8277
8344
|
|
@@ -8484,6 +8551,38 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8484
8551
|
}
|
8485
8552
|
},
|
8486
8553
|
|
8554
|
+
/**
|
8555
|
+
Get the reference for the specified record.
|
8556
|
+
Example
|
8557
|
+
```javascript
|
8558
|
+
var userRef = store.getReference('user', 1);
|
8559
|
+
// check if the user is loaded
|
8560
|
+
var isLoaded = userRef.value() !== null;
|
8561
|
+
// get the record of the reference (null if not yet available)
|
8562
|
+
var user = userRef.value();
|
8563
|
+
// get the identifier of the reference
|
8564
|
+
if (userRef.remoteType() === "id") {
|
8565
|
+
var id = userRef.id();
|
8566
|
+
}
|
8567
|
+
// load user (via store.find)
|
8568
|
+
userRef.load().then(...)
|
8569
|
+
// or trigger a reload
|
8570
|
+
userRef.reload().then(...)
|
8571
|
+
// provide data for reference
|
8572
|
+
userRef.push({ id: 1, username: "@user" }).then(function(user) {
|
8573
|
+
userRef.value() === user;
|
8574
|
+
});
|
8575
|
+
```
|
8576
|
+
@method getReference
|
8577
|
+
@param {String} type
|
8578
|
+
@param {String|Integer} id
|
8579
|
+
@since 2.5.0
|
8580
|
+
@return {RecordReference}
|
8581
|
+
*/
|
8582
|
+
getReference: function (type, id) {
|
8583
|
+
return this._internalModelForId(type, id).recordReference;
|
8584
|
+
},
|
8585
|
+
|
8487
8586
|
/**
|
8488
8587
|
Get a record by a given type and ID without triggering a fetch.
|
8489
8588
|
This method will synchronously return the record if it is available in the store,
|
@@ -8777,7 +8876,7 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8777
8876
|
},
|
8778
8877
|
|
8779
8878
|
/**
|
8780
|
-
`findAll`
|
8879
|
+
`findAll` asks the adapter's `findAll` method to find the records for the
|
8781
8880
|
given type, and returns a promise which will resolve with all records of
|
8782
8881
|
this type present in the store, even if the adapter only returns a subset
|
8783
8882
|
of them.
|
@@ -8792,6 +8891,7 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8792
8891
|
_When_ the returned promise resolves depends on the reload behavior,
|
8793
8892
|
configured via the passed `options` hash and the result of the adapter's
|
8794
8893
|
`shouldReloadAll` method.
|
8894
|
+
### Reloading
|
8795
8895
|
If `{ reload: true }` is passed or `adapter.shouldReloadAll` evaluates to
|
8796
8896
|
`true`, then the returned promise resolves once the adapter returns data,
|
8797
8897
|
regardless if there are already records in the store:
|
@@ -8815,7 +8915,8 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8815
8915
|
```
|
8816
8916
|
If no reload is indicated via the abovementioned ways, then the promise
|
8817
8917
|
immediately resolves with all the records currently loaded in the store.
|
8818
|
-
|
8918
|
+
### Background Reloading
|
8919
|
+
Optionally, if `adapter.shouldBackgroundReloadAll` evaluates to `true`,
|
8819
8920
|
then a background reload is started. Once this resolves, the array with
|
8820
8921
|
which the promise resolves, is updated automatically so it contains all the
|
8821
8922
|
records in the store:
|
@@ -8850,7 +8951,41 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8850
8951
|
// ]
|
8851
8952
|
allAuthors.getEach('id'); // ['first', 'second']
|
8852
8953
|
```
|
8853
|
-
|
8954
|
+
If you would like to force or prevent background reloading, you can set a
|
8955
|
+
boolean value for `backgroundReload` in the options object for
|
8956
|
+
`findAll`.
|
8957
|
+
```app/routes/post/edit.js
|
8958
|
+
import Ember from 'ember';
|
8959
|
+
export default Ember.Route.extend({
|
8960
|
+
model: function() {
|
8961
|
+
return this.store.findAll('post', { backgroundReload: false });
|
8962
|
+
}
|
8963
|
+
});
|
8964
|
+
```
|
8965
|
+
If you pass an object on the `adapterOptions` property of the options
|
8966
|
+
argument it will be passed to you adapter via the `snapshotRecordArray`
|
8967
|
+
```app/routes/posts.js
|
8968
|
+
import Ember from 'ember';
|
8969
|
+
export default Ember.Route.extend({
|
8970
|
+
model: function(params) {
|
8971
|
+
return this.store.findAll('post', {
|
8972
|
+
adapterOptions: { subscribe: false }
|
8973
|
+
});
|
8974
|
+
}
|
8975
|
+
});
|
8976
|
+
```
|
8977
|
+
```app/adapters/post.js
|
8978
|
+
import MyCustomAdapter from './custom-adapter';
|
8979
|
+
export default MyCustomAdapter.extend({
|
8980
|
+
findAll: function(store, type, sinceToken, snapshotRecordArray) {
|
8981
|
+
if (snapshotRecordArray.adapterOptions.subscribe) {
|
8982
|
+
// ...
|
8983
|
+
}
|
8984
|
+
// ...
|
8985
|
+
}
|
8986
|
+
});
|
8987
|
+
```
|
8988
|
+
See [peekAll](#method_peekAll) to get an array of current records in the
|
8854
8989
|
store, without waiting until a reload is finished.
|
8855
8990
|
See [query](#method_query) to only get a subset of records from the server.
|
8856
8991
|
@method findAll
|
@@ -8886,13 +9021,21 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
8886
9021
|
if (options.reload) {
|
8887
9022
|
return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._findAll)(adapter, this, typeClass, sinceToken, options));
|
8888
9023
|
}
|
9024
|
+
|
8889
9025
|
var snapshotArray = array.createSnapshot(options);
|
9026
|
+
|
8890
9027
|
if (adapter.shouldReloadAll(this, snapshotArray)) {
|
8891
9028
|
return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)((0, _emberDataPrivateSystemStoreFinders._findAll)(adapter, this, typeClass, sinceToken, options));
|
8892
9029
|
}
|
8893
|
-
|
9030
|
+
|
9031
|
+
if (options.backgroundReload === false) {
|
9032
|
+
return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)(Promise.resolve(array));
|
9033
|
+
}
|
9034
|
+
|
9035
|
+
if (options.backgroundReload || adapter.shouldBackgroundReloadAll(this, snapshotArray)) {
|
8894
9036
|
(0, _emberDataPrivateSystemStoreFinders._findAll)(adapter, this, typeClass, sinceToken, options);
|
8895
9037
|
}
|
9038
|
+
|
8896
9039
|
return (0, _emberDataPrivateSystemPromiseProxies.promiseArray)(Promise.resolve(array));
|
8897
9040
|
},
|
8898
9041
|
|
@@ -9510,7 +9653,7 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
9510
9653
|
var _this2 = this;
|
9511
9654
|
|
9512
9655
|
var modelName = data.type;
|
9513
|
-
(0, _emberDataPrivateDebug.assert)('You must include an \'id\' for ' + modelName + ' in an object passed to \'push\'', data.id
|
9656
|
+
(0, _emberDataPrivateDebug.assert)('You must include an \'id\' for ' + modelName + ' in an object passed to \'push\'', data.id !== null && data.id !== undefined && data.id !== '');
|
9514
9657
|
(0, _emberDataPrivateDebug.assert)('You tried to push data with a type \'' + modelName + '\' but no model could be found with that name.', this._hasModelFor(modelName));
|
9515
9658
|
|
9516
9659
|
(0, _emberDataPrivateDebug.runInDebug)(function () {
|
@@ -9611,15 +9754,10 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
9611
9754
|
(0, _emberDataPrivateDebug.assert)('Passing classes to store methods has been removed. Please pass a dasherized string instead of ' + _ember.default.inspect(modelName), typeof modelName === 'string');
|
9612
9755
|
serializer = this.serializerFor(modelName);
|
9613
9756
|
}
|
9614
|
-
|
9615
|
-
|
9616
|
-
|
9617
|
-
|
9618
|
-
} else {
|
9619
|
-
this._adapterRun(function () {
|
9620
|
-
return serializer.pushPayload(_this3, payload);
|
9621
|
-
});
|
9622
|
-
}
|
9757
|
+
|
9758
|
+
this._adapterRun(function () {
|
9759
|
+
return serializer.pushPayload(_this3, payload);
|
9760
|
+
});
|
9623
9761
|
},
|
9624
9762
|
|
9625
9763
|
/**
|
@@ -9812,42 +9950,6 @@ define('ember-data/-private/system/store', ['exports', 'ember', 'ember-data/mode
|
|
9812
9950
|
|
9813
9951
|
});
|
9814
9952
|
|
9815
|
-
if (true) {
|
9816
|
-
|
9817
|
-
Store.reopen({
|
9818
|
-
/**
|
9819
|
-
Get the reference for the specified record.
|
9820
|
-
Example
|
9821
|
-
```javascript
|
9822
|
-
var userRef = store.getReference('user', 1);
|
9823
|
-
// check if the user is loaded
|
9824
|
-
var isLoaded = userRef.value() !== null;
|
9825
|
-
// get the record of the reference (null if not yet available)
|
9826
|
-
var user = userRef.value();
|
9827
|
-
// get the identifier of the reference
|
9828
|
-
if (userRef.remoteType() === "id") {
|
9829
|
-
var id = userRef.id();
|
9830
|
-
}
|
9831
|
-
// load user (via store.find)
|
9832
|
-
userRef.load().then(...)
|
9833
|
-
// or trigger a reload
|
9834
|
-
userRef.reload().then(...)
|
9835
|
-
// provide data for reference
|
9836
|
-
userRef.push({ id: 1, username: "@user" }).then(function(user) {
|
9837
|
-
userRef.value() === user;
|
9838
|
-
});
|
9839
|
-
```
|
9840
|
-
@method getReference
|
9841
|
-
@param {String} type
|
9842
|
-
@param {String|Integer} id
|
9843
|
-
@return {RecordReference}
|
9844
|
-
*/
|
9845
|
-
getReference: function (type, id) {
|
9846
|
-
return this._internalModelForId(type, id).recordReference;
|
9847
|
-
}
|
9848
|
-
});
|
9849
|
-
}
|
9850
|
-
|
9851
9953
|
function deserializeRecordId(store, key, relationship, id) {
|
9852
9954
|
if (isNone(id)) {
|
9853
9955
|
return;
|
@@ -10448,12 +10550,8 @@ define('ember-data/-private/transforms/boolean', ['exports', 'ember', 'ember-dat
|
|
10448
10550
|
deserialize: function (serialized, options) {
|
10449
10551
|
var type = typeof serialized;
|
10450
10552
|
|
10451
|
-
if (true) {
|
10452
|
-
|
10453
|
-
if (isNone(serialized) && options.allowNull === true) {
|
10454
|
-
return null;
|
10455
|
-
}
|
10456
|
-
}
|
10553
|
+
if (isNone(serialized) && options.allowNull === true) {
|
10554
|
+
return null;
|
10457
10555
|
}
|
10458
10556
|
|
10459
10557
|
if (type === "boolean") {
|
@@ -10468,25 +10566,21 @@ define('ember-data/-private/transforms/boolean', ['exports', 'ember', 'ember-dat
|
|
10468
10566
|
},
|
10469
10567
|
|
10470
10568
|
serialize: function (deserialized, options) {
|
10471
|
-
if (true) {
|
10472
|
-
|
10473
|
-
if (isNone(deserialized) && options.allowNull === true) {
|
10474
|
-
return null;
|
10475
|
-
}
|
10476
|
-
}
|
10569
|
+
if (isNone(deserialized) && options.allowNull === true) {
|
10570
|
+
return null;
|
10477
10571
|
}
|
10478
10572
|
|
10479
10573
|
return Boolean(deserialized);
|
10480
10574
|
}
|
10481
10575
|
});
|
10482
10576
|
});
|
10483
|
-
define("ember-data/-private/transforms/date", ["exports", "ember
|
10577
|
+
define("ember-data/-private/transforms/date", ["exports", "ember-data/-private/ext/date", "ember-data/transform"], function (exports, _emberDataPrivateExtDate, _emberDataTransform) {
|
10484
10578
|
exports.default = _emberDataTransform.default.extend({
|
10485
10579
|
deserialize: function (serialized) {
|
10486
10580
|
var type = typeof serialized;
|
10487
10581
|
|
10488
10582
|
if (type === "string") {
|
10489
|
-
return new Date(
|
10583
|
+
return new Date((0, _emberDataPrivateExtDate.parseDate)(serialized));
|
10490
10584
|
} else if (type === "number") {
|
10491
10585
|
return new Date(serialized);
|
10492
10586
|
} else if (serialized === null || serialized === undefined) {
|
@@ -10783,8 +10877,8 @@ define('ember-data/adapter', ['exports', 'ember'], function (exports, _ember) {
|
|
10783
10877
|
/**
|
10784
10878
|
The `findRecord()` method is invoked when the store is asked for a record that
|
10785
10879
|
has not previously been loaded. In response to `findRecord()` being called, you
|
10786
|
-
should query your persistence layer for a record with the given ID. The `findRecord`
|
10787
|
-
method should return a promise that will resolve to a JavaScript object that will be
|
10880
|
+
should query your persistence layer for a record with the given ID. The `findRecord`
|
10881
|
+
method should return a promise that will resolve to a JavaScript object that will be
|
10788
10882
|
normalized by the serializer.
|
10789
10883
|
Here is an example `findRecord` implementation:
|
10790
10884
|
```app/adapters/application.js
|
@@ -11274,9 +11368,6 @@ define('ember-data/adapters/errors', ['exports', 'ember', 'ember-data/-private/d
|
|
11274
11368
|
}
|
11275
11369
|
|
11276
11370
|
var extendedErrorsEnabled = false;
|
11277
|
-
if (false) {
|
11278
|
-
extendedErrorsEnabled = true;
|
11279
|
-
}
|
11280
11371
|
|
11281
11372
|
function extendFn(ErrorClass) {
|
11282
11373
|
return function () {
|
@@ -11564,12 +11655,7 @@ define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters
|
|
11564
11655
|
@return {Promise} promise
|
11565
11656
|
*/
|
11566
11657
|
findMany: function (store, type, ids, snapshots) {
|
11567
|
-
|
11568
|
-
return this._super.apply(this, arguments);
|
11569
|
-
} else {
|
11570
|
-
var url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
|
11571
|
-
return this.ajax(url, 'GET', { data: { filter: { id: ids.join(',') } } });
|
11572
|
-
}
|
11658
|
+
return this._super.apply(this, arguments);
|
11573
11659
|
},
|
11574
11660
|
|
11575
11661
|
/**
|
@@ -11591,80 +11677,65 @@ define('ember-data/adapters/json-api', ['exports', 'ember', 'ember-data/adapters
|
|
11591
11677
|
@return {Promise} promise
|
11592
11678
|
*/
|
11593
11679
|
updateRecord: function (store, type, snapshot) {
|
11594
|
-
|
11595
|
-
return this._super.apply(this, arguments);
|
11596
|
-
} else {
|
11597
|
-
var data = {};
|
11598
|
-
var serializer = store.serializerFor(type.modelName);
|
11599
|
-
|
11600
|
-
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
|
11601
|
-
|
11602
|
-
var id = snapshot.id;
|
11603
|
-
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
|
11604
|
-
|
11605
|
-
return this.ajax(url, 'PATCH', { data: data });
|
11606
|
-
}
|
11680
|
+
return this._super.apply(this, arguments);
|
11607
11681
|
}
|
11608
11682
|
});
|
11609
11683
|
|
11610
|
-
|
11684
|
+
JSONAPIAdapter.reopen({
|
11611
11685
|
|
11612
|
-
|
11686
|
+
methodForRequest: function (params) {
|
11687
|
+
if (params.requestType === 'updateRecord') {
|
11688
|
+
return 'PATCH';
|
11689
|
+
}
|
11613
11690
|
|
11614
|
-
|
11615
|
-
|
11616
|
-
return 'PATCH';
|
11617
|
-
}
|
11691
|
+
return this._super.apply(this, arguments);
|
11692
|
+
},
|
11618
11693
|
|
11619
|
-
|
11620
|
-
|
11621
|
-
|
11622
|
-
dataForRequest: function (params) {
|
11623
|
-
var requestType = params.requestType;
|
11624
|
-
var ids = params.ids;
|
11625
|
-
|
11626
|
-
if (requestType === 'findMany') {
|
11627
|
-
return {
|
11628
|
-
filter: { id: ids.join(',') }
|
11629
|
-
};
|
11630
|
-
}
|
11694
|
+
dataForRequest: function (params) {
|
11695
|
+
var requestType = params.requestType;
|
11696
|
+
var ids = params.ids;
|
11631
11697
|
|
11632
|
-
|
11633
|
-
|
11634
|
-
|
11635
|
-
|
11698
|
+
if (requestType === 'findMany') {
|
11699
|
+
return {
|
11700
|
+
filter: { id: ids.join(',') }
|
11701
|
+
};
|
11702
|
+
}
|
11636
11703
|
|
11637
|
-
|
11638
|
-
|
11704
|
+
if (requestType === 'updateRecord') {
|
11705
|
+
var store = params.store;
|
11706
|
+
var type = params.type;
|
11707
|
+
var snapshot = params.snapshot;
|
11639
11708
|
|
11640
|
-
|
11709
|
+
var data = {};
|
11710
|
+
var serializer = store.serializerFor(type.modelName);
|
11641
11711
|
|
11642
|
-
|
11643
|
-
}
|
11712
|
+
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
|
11644
11713
|
|
11645
|
-
return
|
11646
|
-
}
|
11714
|
+
return data;
|
11715
|
+
}
|
11647
11716
|
|
11648
|
-
|
11649
|
-
|
11717
|
+
return this._super.apply(this, arguments);
|
11718
|
+
},
|
11650
11719
|
|
11651
|
-
|
11720
|
+
headersForRequest: function () {
|
11721
|
+
var headers = this._super.apply(this, arguments) || {};
|
11652
11722
|
|
11653
|
-
|
11654
|
-
},
|
11723
|
+
headers['Accept'] = 'application/vnd.api+json';
|
11655
11724
|
|
11656
|
-
|
11657
|
-
|
11725
|
+
return headers;
|
11726
|
+
},
|
11658
11727
|
|
11659
|
-
|
11660
|
-
|
11661
|
-
}
|
11728
|
+
_requestToJQueryAjaxHash: function () {
|
11729
|
+
var hash = this._super.apply(this, arguments);
|
11662
11730
|
|
11663
|
-
|
11731
|
+
if (hash.contentType) {
|
11732
|
+
hash.contentType = 'application/vnd.api+json';
|
11664
11733
|
}
|
11665
11734
|
|
11666
|
-
|
11667
|
-
|
11735
|
+
return hash;
|
11736
|
+
}
|
11737
|
+
|
11738
|
+
});
|
11668
11739
|
|
11669
11740
|
exports.default = JSONAPIAdapter;
|
11670
11741
|
});
|
@@ -12032,19 +12103,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12032
12103
|
@return {Promise} promise
|
12033
12104
|
*/
|
12034
12105
|
findRecord: function (store, type, id, snapshot) {
|
12035
|
-
|
12036
|
-
|
12037
|
-
|
12038
|
-
|
12039
|
-
});
|
12040
|
-
|
12041
|
-
return this._makeRequest(request);
|
12042
|
-
} else {
|
12043
|
-
var url = this.buildURL(type.modelName, id, snapshot, 'findRecord');
|
12044
|
-
var query = this.buildQuery(snapshot);
|
12106
|
+
var request = this._requestFor({
|
12107
|
+
store: store, type: type, id: id, snapshot: snapshot,
|
12108
|
+
requestType: 'findRecord'
|
12109
|
+
});
|
12045
12110
|
|
12046
|
-
|
12047
|
-
}
|
12111
|
+
return this._makeRequest(request);
|
12048
12112
|
},
|
12049
12113
|
|
12050
12114
|
/**
|
@@ -12062,23 +12126,13 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12062
12126
|
findAll: function (store, type, sinceToken, snapshotRecordArray) {
|
12063
12127
|
var query = this.buildQuery(snapshotRecordArray);
|
12064
12128
|
|
12065
|
-
|
12066
|
-
|
12067
|
-
|
12068
|
-
|
12069
|
-
|
12070
|
-
});
|
12071
|
-
|
12072
|
-
return this._makeRequest(request);
|
12073
|
-
} else {
|
12074
|
-
var url = this.buildURL(type.modelName, null, snapshotRecordArray, 'findAll');
|
12075
|
-
|
12076
|
-
if (sinceToken) {
|
12077
|
-
query.since = sinceToken;
|
12078
|
-
}
|
12129
|
+
var request = this._requestFor({
|
12130
|
+
store: store, type: type, sinceToken: sinceToken, query: query,
|
12131
|
+
snapshots: snapshotRecordArray,
|
12132
|
+
requestType: 'findAll'
|
12133
|
+
});
|
12079
12134
|
|
12080
|
-
|
12081
|
-
}
|
12135
|
+
return this._makeRequest(request);
|
12082
12136
|
},
|
12083
12137
|
|
12084
12138
|
/**
|
@@ -12096,22 +12150,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12096
12150
|
@return {Promise} promise
|
12097
12151
|
*/
|
12098
12152
|
query: function (store, type, query) {
|
12099
|
-
|
12100
|
-
|
12101
|
-
|
12102
|
-
|
12103
|
-
});
|
12104
|
-
|
12105
|
-
return this._makeRequest(request);
|
12106
|
-
} else {
|
12107
|
-
var url = this.buildURL(type.modelName, null, null, 'query', query);
|
12108
|
-
|
12109
|
-
if (this.sortQueryParams) {
|
12110
|
-
query = this.sortQueryParams(query);
|
12111
|
-
}
|
12153
|
+
var request = this._requestFor({
|
12154
|
+
store: store, type: type, query: query,
|
12155
|
+
requestType: 'query'
|
12156
|
+
});
|
12112
12157
|
|
12113
|
-
|
12114
|
-
}
|
12158
|
+
return this._makeRequest(request);
|
12115
12159
|
},
|
12116
12160
|
|
12117
12161
|
/**
|
@@ -12129,22 +12173,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12129
12173
|
@return {Promise} promise
|
12130
12174
|
*/
|
12131
12175
|
queryRecord: function (store, type, query) {
|
12132
|
-
|
12133
|
-
|
12134
|
-
|
12135
|
-
|
12136
|
-
});
|
12137
|
-
|
12138
|
-
return this._makeRequest(request);
|
12139
|
-
} else {
|
12140
|
-
var url = this.buildURL(type.modelName, null, null, 'queryRecord', query);
|
12141
|
-
|
12142
|
-
if (this.sortQueryParams) {
|
12143
|
-
query = this.sortQueryParams(query);
|
12144
|
-
}
|
12176
|
+
var request = this._requestFor({
|
12177
|
+
store: store, type: type, query: query,
|
12178
|
+
requestType: 'queryRecord'
|
12179
|
+
});
|
12145
12180
|
|
12146
|
-
|
12147
|
-
}
|
12181
|
+
return this._makeRequest(request);
|
12148
12182
|
},
|
12149
12183
|
|
12150
12184
|
/**
|
@@ -12174,17 +12208,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12174
12208
|
@return {Promise} promise
|
12175
12209
|
*/
|
12176
12210
|
findMany: function (store, type, ids, snapshots) {
|
12177
|
-
|
12178
|
-
|
12179
|
-
|
12180
|
-
|
12181
|
-
});
|
12211
|
+
var request = this._requestFor({
|
12212
|
+
store: store, type: type, ids: ids, snapshots: snapshots,
|
12213
|
+
requestType: 'findMany'
|
12214
|
+
});
|
12182
12215
|
|
12183
|
-
|
12184
|
-
} else {
|
12185
|
-
var url = this.buildURL(type.modelName, ids, snapshots, 'findMany');
|
12186
|
-
return this.ajax(url, 'GET', { data: { ids: ids } });
|
12187
|
-
}
|
12216
|
+
return this._makeRequest(request);
|
12188
12217
|
},
|
12189
12218
|
|
12190
12219
|
/**
|
@@ -12214,21 +12243,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12214
12243
|
@return {Promise} promise
|
12215
12244
|
*/
|
12216
12245
|
findHasMany: function (store, snapshot, url, relationship) {
|
12217
|
-
|
12218
|
-
|
12219
|
-
|
12220
|
-
|
12221
|
-
});
|
12222
|
-
|
12223
|
-
return this._makeRequest(request);
|
12224
|
-
} else {
|
12225
|
-
var id = snapshot.id;
|
12226
|
-
var type = snapshot.modelName;
|
12227
|
-
|
12228
|
-
url = this.urlPrefix(url, this.buildURL(type, id, snapshot, 'findHasMany'));
|
12246
|
+
var request = this._requestFor({
|
12247
|
+
store: store, snapshot: snapshot, url: url, relationship: relationship,
|
12248
|
+
requestType: 'findHasMany'
|
12249
|
+
});
|
12229
12250
|
|
12230
|
-
|
12231
|
-
}
|
12251
|
+
return this._makeRequest(request);
|
12232
12252
|
},
|
12233
12253
|
|
12234
12254
|
/**
|
@@ -12258,20 +12278,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12258
12278
|
@return {Promise} promise
|
12259
12279
|
*/
|
12260
12280
|
findBelongsTo: function (store, snapshot, url, relationship) {
|
12261
|
-
|
12262
|
-
|
12263
|
-
|
12264
|
-
|
12265
|
-
});
|
12266
|
-
|
12267
|
-
return this._makeRequest(request);
|
12268
|
-
} else {
|
12269
|
-
var id = snapshot.id;
|
12270
|
-
var type = snapshot.modelName;
|
12281
|
+
var request = this._requestFor({
|
12282
|
+
store: store, snapshot: snapshot, url: url, relationship: relationship,
|
12283
|
+
requestType: 'findBelongsTo'
|
12284
|
+
});
|
12271
12285
|
|
12272
|
-
|
12273
|
-
return this.ajax(url, 'GET');
|
12274
|
-
}
|
12286
|
+
return this._makeRequest(request);
|
12275
12287
|
},
|
12276
12288
|
|
12277
12289
|
/**
|
@@ -12288,22 +12300,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12288
12300
|
@return {Promise} promise
|
12289
12301
|
*/
|
12290
12302
|
createRecord: function (store, type, snapshot) {
|
12291
|
-
|
12292
|
-
|
12293
|
-
|
12294
|
-
|
12295
|
-
});
|
12296
|
-
|
12297
|
-
return this._makeRequest(request);
|
12298
|
-
} else {
|
12299
|
-
var data = {};
|
12300
|
-
var serializer = store.serializerFor(type.modelName);
|
12301
|
-
var url = this.buildURL(type.modelName, null, snapshot, 'createRecord');
|
12302
|
-
|
12303
|
-
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
|
12303
|
+
var request = this._requestFor({
|
12304
|
+
store: store, type: type, snapshot: snapshot,
|
12305
|
+
requestType: 'createRecord'
|
12306
|
+
});
|
12304
12307
|
|
12305
|
-
|
12306
|
-
}
|
12308
|
+
return this._makeRequest(request);
|
12307
12309
|
},
|
12308
12310
|
|
12309
12311
|
/**
|
@@ -12320,24 +12322,12 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12320
12322
|
@return {Promise} promise
|
12321
12323
|
*/
|
12322
12324
|
updateRecord: function (store, type, snapshot) {
|
12323
|
-
|
12324
|
-
|
12325
|
-
|
12326
|
-
|
12327
|
-
});
|
12328
|
-
|
12329
|
-
return this._makeRequest(request);
|
12330
|
-
} else {
|
12331
|
-
var data = {};
|
12332
|
-
var serializer = store.serializerFor(type.modelName);
|
12333
|
-
|
12334
|
-
serializer.serializeIntoHash(data, type, snapshot);
|
12335
|
-
|
12336
|
-
var id = snapshot.id;
|
12337
|
-
var url = this.buildURL(type.modelName, id, snapshot, 'updateRecord');
|
12325
|
+
var request = this._requestFor({
|
12326
|
+
store: store, type: type, snapshot: snapshot,
|
12327
|
+
requestType: 'updateRecord'
|
12328
|
+
});
|
12338
12329
|
|
12339
|
-
|
12340
|
-
}
|
12330
|
+
return this._makeRequest(request);
|
12341
12331
|
},
|
12342
12332
|
|
12343
12333
|
/**
|
@@ -12350,28 +12340,26 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12350
12340
|
@return {Promise} promise
|
12351
12341
|
*/
|
12352
12342
|
deleteRecord: function (store, type, snapshot) {
|
12353
|
-
|
12354
|
-
|
12355
|
-
|
12356
|
-
|
12357
|
-
});
|
12358
|
-
|
12359
|
-
return this._makeRequest(request);
|
12360
|
-
} else {
|
12361
|
-
var id = snapshot.id;
|
12343
|
+
var request = this._requestFor({
|
12344
|
+
store: store, type: type, snapshot: snapshot,
|
12345
|
+
requestType: 'deleteRecord'
|
12346
|
+
});
|
12362
12347
|
|
12363
|
-
|
12364
|
-
}
|
12348
|
+
return this._makeRequest(request);
|
12365
12349
|
},
|
12366
12350
|
|
12367
12351
|
_stripIDFromURL: function (store, snapshot) {
|
12368
12352
|
var url = this.buildURL(snapshot.modelName, snapshot.id, snapshot);
|
12369
12353
|
|
12370
12354
|
var expandedURL = url.split('/');
|
12371
|
-
//Case when the url is of the format ...something/:id
|
12355
|
+
// Case when the url is of the format ...something/:id
|
12356
|
+
// We are decodeURIComponent-ing the lastSegment because if it represents
|
12357
|
+
// the id, it has been encodeURIComponent-ified within `buildURL`. If we
|
12358
|
+
// don't do this, then records with id having special characters are not
|
12359
|
+
// coalesced correctly (see GH #4190 for the reported bug)
|
12372
12360
|
var lastSegment = expandedURL[expandedURL.length - 1];
|
12373
12361
|
var id = snapshot.id;
|
12374
|
-
if (lastSegment === id) {
|
12362
|
+
if (decodeURIComponent(lastSegment) === id) {
|
12375
12363
|
expandedURL[expandedURL.length - 1] = "";
|
12376
12364
|
} else if (endsWith(lastSegment, '?id=' + id)) {
|
12377
12365
|
//Case when the url is of the format ...something?id=:id
|
@@ -12481,23 +12469,6 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12481
12469
|
var errors = this.normalizeErrorResponse(status, headers, payload);
|
12482
12470
|
var detailedMessage = this.generatedDetailedMessage(status, headers, payload, requestData);
|
12483
12471
|
|
12484
|
-
if (false) {
|
12485
|
-
switch (status) {
|
12486
|
-
case 401:
|
12487
|
-
return new _emberDataAdaptersErrors.UnauthorizedError(errors, detailedMessage);
|
12488
|
-
case 403:
|
12489
|
-
return new _emberDataAdaptersErrors.ForbiddenError(errors, detailedMessage);
|
12490
|
-
case 404:
|
12491
|
-
return new _emberDataAdaptersErrors.NotFoundError(errors, detailedMessage);
|
12492
|
-
case 409:
|
12493
|
-
return new _emberDataAdaptersErrors.ConflictError(errors, detailedMessage);
|
12494
|
-
default:
|
12495
|
-
if (status >= 500) {
|
12496
|
-
return new _emberDataAdaptersErrors.ServerError(errors, detailedMessage);
|
12497
|
-
}
|
12498
|
-
}
|
12499
|
-
}
|
12500
|
-
|
12501
12472
|
return new _emberDataAdaptersErrors.AdapterError(errors, detailedMessage);
|
12502
12473
|
},
|
12503
12474
|
|
@@ -12649,7 +12620,9 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12649
12620
|
|
12650
12621
|
try {
|
12651
12622
|
json = _ember.default.$.parseJSON(responseText);
|
12652
|
-
} catch (e) {
|
12623
|
+
} catch (e) {
|
12624
|
+
// ignored
|
12625
|
+
}
|
12653
12626
|
|
12654
12627
|
return json;
|
12655
12628
|
},
|
@@ -12704,13 +12677,11 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12704
12677
|
buildQuery: function (snapshot) {
|
12705
12678
|
var query = {};
|
12706
12679
|
|
12707
|
-
if (
|
12708
|
-
|
12709
|
-
var include = snapshot.include;
|
12680
|
+
if (snapshot) {
|
12681
|
+
var include = snapshot.include;
|
12710
12682
|
|
12711
|
-
|
12712
|
-
|
12713
|
-
}
|
12683
|
+
if (include) {
|
12684
|
+
query.include = include;
|
12714
12685
|
}
|
12715
12686
|
}
|
12716
12687
|
|
@@ -12718,265 +12689,264 @@ define('ember-data/adapters/rest', ['exports', 'ember', 'ember-data/adapter', 'e
|
|
12718
12689
|
}
|
12719
12690
|
});
|
12720
12691
|
|
12721
|
-
|
12722
|
-
|
12723
|
-
RESTAdapter.reopen({
|
12692
|
+
RESTAdapter.reopen({
|
12724
12693
|
|
12725
|
-
|
12726
|
-
|
12727
|
-
|
12728
|
-
|
12729
|
-
|
12730
|
-
|
12731
|
-
|
12732
|
-
|
12733
|
-
|
12734
|
-
|
12735
|
-
|
12736
|
-
|
12737
|
-
|
12738
|
-
|
12694
|
+
/**
|
12695
|
+
* Get the data (body or query params) for a request.
|
12696
|
+
*
|
12697
|
+
* @public
|
12698
|
+
* @method dataForRequest
|
12699
|
+
* @param {Object} params
|
12700
|
+
* @return {Object} data
|
12701
|
+
*/
|
12702
|
+
dataForRequest: function (params) {
|
12703
|
+
var store = params.store;
|
12704
|
+
var type = params.type;
|
12705
|
+
var snapshot = params.snapshot;
|
12706
|
+
var requestType = params.requestType;
|
12707
|
+
var query = params.query;
|
12739
12708
|
|
12740
|
-
|
12741
|
-
|
12709
|
+
// type is not passed to findBelongsTo and findHasMany
|
12710
|
+
type = type || snapshot && snapshot.type;
|
12742
12711
|
|
12743
|
-
|
12744
|
-
|
12712
|
+
var serializer = store.serializerFor(type.modelName);
|
12713
|
+
var data = {};
|
12745
12714
|
|
12746
|
-
|
12747
|
-
|
12748
|
-
|
12749
|
-
|
12715
|
+
switch (requestType) {
|
12716
|
+
case 'createRecord':
|
12717
|
+
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });
|
12718
|
+
break;
|
12750
12719
|
|
12751
|
-
|
12752
|
-
|
12753
|
-
|
12720
|
+
case 'updateRecord':
|
12721
|
+
serializer.serializeIntoHash(data, type, snapshot);
|
12722
|
+
break;
|
12754
12723
|
|
12755
|
-
|
12756
|
-
|
12757
|
-
|
12724
|
+
case 'findRecord':
|
12725
|
+
data = this.buildQuery(snapshot);
|
12726
|
+
break;
|
12758
12727
|
|
12759
|
-
|
12760
|
-
|
12761
|
-
|
12762
|
-
|
12763
|
-
|
12764
|
-
|
12765
|
-
|
12728
|
+
case 'findAll':
|
12729
|
+
if (params.sinceToken) {
|
12730
|
+
query = query || {};
|
12731
|
+
query.since = params.sinceToken;
|
12732
|
+
}
|
12733
|
+
data = query;
|
12734
|
+
break;
|
12766
12735
|
|
12767
|
-
|
12768
|
-
|
12769
|
-
|
12770
|
-
|
12771
|
-
|
12772
|
-
|
12773
|
-
|
12736
|
+
case 'query':
|
12737
|
+
case 'queryRecord':
|
12738
|
+
if (this.sortQueryParams) {
|
12739
|
+
query = this.sortQueryParams(query);
|
12740
|
+
}
|
12741
|
+
data = query;
|
12742
|
+
break;
|
12774
12743
|
|
12775
|
-
|
12776
|
-
|
12777
|
-
|
12744
|
+
case 'findMany':
|
12745
|
+
data = { ids: params.ids };
|
12746
|
+
break;
|
12778
12747
|
|
12779
|
-
|
12780
|
-
|
12781
|
-
|
12782
|
-
|
12748
|
+
default:
|
12749
|
+
data = undefined;
|
12750
|
+
break;
|
12751
|
+
}
|
12783
12752
|
|
12784
|
-
|
12785
|
-
|
12753
|
+
return data;
|
12754
|
+
},
|
12786
12755
|
|
12787
|
-
|
12788
|
-
|
12789
|
-
|
12790
|
-
|
12791
|
-
|
12792
|
-
|
12793
|
-
|
12794
|
-
|
12795
|
-
|
12796
|
-
|
12797
|
-
|
12798
|
-
switch (requestType) {
|
12799
|
-
case 'createRecord':
|
12800
|
-
return 'POST';
|
12801
|
-
case 'updateRecord':
|
12802
|
-
return 'PUT';
|
12803
|
-
case 'deleteRecord':
|
12804
|
-
return 'DELETE';
|
12805
|
-
}
|
12756
|
+
/**
|
12757
|
+
* Get the HTTP method for a request.
|
12758
|
+
*
|
12759
|
+
* @public
|
12760
|
+
* @method methodForRequest
|
12761
|
+
* @param {Object} params
|
12762
|
+
* @return {String} HTTP method
|
12763
|
+
*/
|
12764
|
+
methodForRequest: function (params) {
|
12765
|
+
var requestType = params.requestType;
|
12806
12766
|
|
12807
|
-
|
12808
|
-
|
12767
|
+
switch (requestType) {
|
12768
|
+
case 'createRecord':
|
12769
|
+
return 'POST';
|
12770
|
+
case 'updateRecord':
|
12771
|
+
return 'PUT';
|
12772
|
+
case 'deleteRecord':
|
12773
|
+
return 'DELETE';
|
12774
|
+
}
|
12809
12775
|
|
12810
|
-
|
12811
|
-
|
12812
|
-
*
|
12813
|
-
* @public
|
12814
|
-
* @method urlForRequest
|
12815
|
-
* @param {Object} params
|
12816
|
-
* @return {String} URL
|
12817
|
-
*/
|
12818
|
-
urlForRequest: function (params) {
|
12819
|
-
var type = params.type;
|
12820
|
-
var id = params.id;
|
12821
|
-
var ids = params.ids;
|
12822
|
-
var snapshot = params.snapshot;
|
12823
|
-
var snapshots = params.snapshots;
|
12824
|
-
var requestType = params.requestType;
|
12825
|
-
var query = params.query;
|
12776
|
+
return 'GET';
|
12777
|
+
},
|
12826
12778
|
|
12827
|
-
|
12828
|
-
|
12829
|
-
|
12830
|
-
|
12779
|
+
/**
|
12780
|
+
* Get the URL for a request.
|
12781
|
+
*
|
12782
|
+
* @public
|
12783
|
+
* @method urlForRequest
|
12784
|
+
* @param {Object} params
|
12785
|
+
* @return {String} URL
|
12786
|
+
*/
|
12787
|
+
urlForRequest: function (params) {
|
12788
|
+
var type = params.type;
|
12789
|
+
var id = params.id;
|
12790
|
+
var ids = params.ids;
|
12791
|
+
var snapshot = params.snapshot;
|
12792
|
+
var snapshots = params.snapshots;
|
12793
|
+
var requestType = params.requestType;
|
12794
|
+
var query = params.query;
|
12795
|
+
|
12796
|
+
// type and id are not passed from updateRecord and deleteRecord, hence they
|
12797
|
+
// are defined if not set
|
12798
|
+
type = type || snapshot && snapshot.type;
|
12799
|
+
id = id || snapshot && snapshot.id;
|
12831
12800
|
|
12832
|
-
|
12833
|
-
|
12834
|
-
|
12801
|
+
switch (requestType) {
|
12802
|
+
case 'findAll':
|
12803
|
+
return this.buildURL(type.modelName, null, snapshots, requestType);
|
12835
12804
|
|
12836
|
-
|
12837
|
-
|
12838
|
-
|
12805
|
+
case 'query':
|
12806
|
+
case 'queryRecord':
|
12807
|
+
return this.buildURL(type.modelName, null, null, requestType, query);
|
12839
12808
|
|
12840
|
-
|
12841
|
-
|
12809
|
+
case 'findMany':
|
12810
|
+
return this.buildURL(type.modelName, ids, snapshots, requestType);
|
12842
12811
|
|
12843
|
-
|
12844
|
-
|
12812
|
+
case 'findHasMany':
|
12813
|
+
case 'findBelongsTo':
|
12814
|
+
{
|
12845
12815
|
var url = this.buildURL(type.modelName, id, snapshot, requestType);
|
12846
12816
|
return this.urlPrefix(params.url, url);
|
12847
|
-
|
12817
|
+
}
|
12818
|
+
}
|
12848
12819
|
|
12849
|
-
|
12850
|
-
|
12820
|
+
return this.buildURL(type.modelName, id, snapshot, requestType, query);
|
12821
|
+
},
|
12851
12822
|
|
12852
|
-
|
12853
|
-
|
12854
|
-
|
12855
|
-
|
12856
|
-
|
12857
|
-
|
12858
|
-
|
12859
|
-
|
12860
|
-
|
12861
|
-
|
12862
|
-
|
12863
|
-
|
12864
|
-
|
12865
|
-
|
12823
|
+
/**
|
12824
|
+
* Get the headers for a request.
|
12825
|
+
*
|
12826
|
+
* By default the value of the `headers` property of the adapter is
|
12827
|
+
* returned.
|
12828
|
+
*
|
12829
|
+
* @public
|
12830
|
+
* @method headersForRequest
|
12831
|
+
* @param {Object} params
|
12832
|
+
* @return {Object} headers
|
12833
|
+
*/
|
12834
|
+
headersForRequest: function (params) {
|
12835
|
+
return this.get('headers');
|
12836
|
+
},
|
12866
12837
|
|
12867
|
-
|
12868
|
-
|
12869
|
-
|
12870
|
-
|
12871
|
-
|
12872
|
-
|
12873
|
-
|
12874
|
-
|
12875
|
-
|
12876
|
-
|
12877
|
-
|
12878
|
-
|
12879
|
-
|
12880
|
-
|
12881
|
-
|
12882
|
-
return { method: method, url: url, headers: headers, data: data };
|
12883
|
-
},
|
12838
|
+
/**
|
12839
|
+
* Get an object which contains all properties for a request which should
|
12840
|
+
* be made.
|
12841
|
+
*
|
12842
|
+
* @private
|
12843
|
+
* @method _requestFor
|
12844
|
+
* @param {Object} params
|
12845
|
+
* @return {Object} request object
|
12846
|
+
*/
|
12847
|
+
_requestFor: function (params) {
|
12848
|
+
var method = this.methodForRequest(params);
|
12849
|
+
var url = this.urlForRequest(params);
|
12850
|
+
var headers = this.headersForRequest(params);
|
12851
|
+
var data = this.dataForRequest(params);
|
12884
12852
|
|
12885
|
-
|
12886
|
-
|
12887
|
-
*
|
12888
|
-
* @private
|
12889
|
-
* @method _requestToJQueryAjaxHash
|
12890
|
-
* @param {Object} request
|
12891
|
-
* @return {Object} jQuery ajax hash
|
12892
|
-
*/
|
12893
|
-
_requestToJQueryAjaxHash: function (request) {
|
12894
|
-
var hash = {};
|
12895
|
-
|
12896
|
-
hash.type = request.method;
|
12897
|
-
hash.url = request.url;
|
12898
|
-
hash.dataType = 'json';
|
12899
|
-
hash.context = this;
|
12900
|
-
|
12901
|
-
if (request.data) {
|
12902
|
-
if (request.type !== 'GET') {
|
12903
|
-
hash.contentType = 'application/json; charset=utf-8';
|
12904
|
-
hash.data = JSON.stringify(request.data);
|
12905
|
-
} else {
|
12906
|
-
hash.data = request.data;
|
12907
|
-
}
|
12908
|
-
}
|
12853
|
+
return { method: method, url: url, headers: headers, data: data };
|
12854
|
+
},
|
12909
12855
|
|
12910
|
-
|
12911
|
-
|
12912
|
-
|
12913
|
-
|
12914
|
-
|
12915
|
-
|
12916
|
-
|
12856
|
+
/**
|
12857
|
+
* Convert a request object into a hash which can be passed to `jQuery.ajax`.
|
12858
|
+
*
|
12859
|
+
* @private
|
12860
|
+
* @method _requestToJQueryAjaxHash
|
12861
|
+
* @param {Object} request
|
12862
|
+
* @return {Object} jQuery ajax hash
|
12863
|
+
*/
|
12864
|
+
_requestToJQueryAjaxHash: function (request) {
|
12865
|
+
var hash = {};
|
12866
|
+
|
12867
|
+
hash.type = request.method;
|
12868
|
+
hash.url = request.url;
|
12869
|
+
hash.dataType = 'json';
|
12870
|
+
hash.context = this;
|
12871
|
+
|
12872
|
+
if (request.data) {
|
12873
|
+
if (request.type !== 'GET') {
|
12874
|
+
hash.contentType = 'application/json; charset=utf-8';
|
12875
|
+
hash.data = JSON.stringify(request.data);
|
12876
|
+
} else {
|
12877
|
+
hash.data = request.data;
|
12917
12878
|
}
|
12879
|
+
}
|
12918
12880
|
|
12919
|
-
|
12920
|
-
|
12881
|
+
var headers = request.headers;
|
12882
|
+
if (headers !== undefined) {
|
12883
|
+
hash.beforeSend = function (xhr) {
|
12884
|
+
Object.keys(headers).forEach(function (key) {
|
12885
|
+
return xhr.setRequestHeader(key, headers[key]);
|
12886
|
+
});
|
12887
|
+
};
|
12888
|
+
}
|
12889
|
+
|
12890
|
+
return hash;
|
12891
|
+
},
|
12921
12892
|
|
12922
|
-
|
12923
|
-
|
12924
|
-
|
12925
|
-
|
12926
|
-
|
12927
|
-
|
12928
|
-
|
12929
|
-
|
12930
|
-
|
12931
|
-
|
12932
|
-
|
12893
|
+
/**
|
12894
|
+
* Make a request using `jQuery.ajax`.
|
12895
|
+
*
|
12896
|
+
* @private
|
12897
|
+
* @method _makeRequest
|
12898
|
+
* @param {Object} request
|
12899
|
+
* @return {Promise} promise
|
12900
|
+
*/
|
12901
|
+
_makeRequest: function (request) {
|
12902
|
+
var adapter = this;
|
12903
|
+
var hash = this._requestToJQueryAjaxHash(request);
|
12933
12904
|
|
12934
|
-
|
12935
|
-
|
12905
|
+
var method = request.method;
|
12906
|
+
var url = request.url;
|
12936
12907
|
|
12937
|
-
|
12908
|
+
var requestData = { method: method, url: url };
|
12938
12909
|
|
12939
|
-
|
12910
|
+
return new _ember.default.RSVP.Promise(function (resolve, reject) {
|
12940
12911
|
|
12941
|
-
|
12942
|
-
|
12912
|
+
hash.success = function (payload, textStatus, jqXHR) {
|
12913
|
+
var response = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), payload, requestData);
|
12943
12914
|
|
12944
|
-
|
12945
|
-
|
12946
|
-
|
12947
|
-
|
12948
|
-
|
12949
|
-
|
12915
|
+
if (response instanceof _emberDataAdaptersErrors.AdapterError) {
|
12916
|
+
_ember.default.run.join(null, reject, response);
|
12917
|
+
} else {
|
12918
|
+
_ember.default.run.join(null, resolve, response);
|
12919
|
+
}
|
12920
|
+
};
|
12950
12921
|
|
12951
|
-
|
12952
|
-
|
12953
|
-
|
12954
|
-
|
12955
|
-
|
12956
|
-
|
12957
|
-
});
|
12922
|
+
hash.error = function (jqXHR, textStatus, errorThrown) {
|
12923
|
+
(0, _emberDataPrivateDebug.runInDebug)(function () {
|
12924
|
+
var message = 'The server returned an empty string for ' + method + ' ' + url + ', which cannot be parsed into a valid JSON. Return either null or {}.';
|
12925
|
+
var validJSONString = !(textStatus === "parsererror" && jqXHR.responseText === "");
|
12926
|
+
(0, _emberDataPrivateDebug.warn)(message, validJSONString, {
|
12927
|
+
id: 'ds.adapter.returned-empty-string-as-JSON'
|
12958
12928
|
});
|
12929
|
+
});
|
12959
12930
|
|
12960
|
-
|
12931
|
+
var error = undefined;
|
12961
12932
|
|
12962
|
-
|
12963
|
-
|
12964
|
-
|
12965
|
-
|
12966
|
-
|
12967
|
-
|
12968
|
-
|
12969
|
-
|
12970
|
-
|
12933
|
+
if (errorThrown instanceof Error) {
|
12934
|
+
error = errorThrown;
|
12935
|
+
} else if (textStatus === 'timeout') {
|
12936
|
+
error = new _emberDataAdaptersErrors.TimeoutError();
|
12937
|
+
} else if (textStatus === 'abort') {
|
12938
|
+
error = new _emberDataAdaptersErrors.AbortError();
|
12939
|
+
} else {
|
12940
|
+
error = adapter.handleResponse(jqXHR.status, (0, _emberDataPrivateUtilsParseResponseHeaders.default)(jqXHR.getAllResponseHeaders()), adapter.parseErrorResponse(jqXHR.responseText) || errorThrown, requestData);
|
12941
|
+
}
|
12971
12942
|
|
12972
|
-
|
12973
|
-
|
12943
|
+
_ember.default.run.join(null, reject, error);
|
12944
|
+
};
|
12974
12945
|
|
12975
|
-
|
12976
|
-
|
12977
|
-
|
12978
|
-
|
12979
|
-
}
|
12946
|
+
adapter._ajaxRequest(hash);
|
12947
|
+
}, 'DS: RESTAdapter#makeRequest: ' + method + ' ' + url);
|
12948
|
+
}
|
12949
|
+
});
|
12980
12950
|
|
12981
12951
|
//From http://stackoverflow.com/questions/280634/endswith-in-javascript
|
12982
12952
|
function endsWith(string, suffix) {
|
@@ -13069,6 +13039,34 @@ define('ember-data/attr', ['exports', 'ember', 'ember-data/-private/debug'], fun
|
|
13069
13039
|
});
|
13070
13040
|
```
|
13071
13041
|
|
13042
|
+
The `options` hash is passed as second argument to a transforms'
|
13043
|
+
`serialize` and `deserialize` method. This allows to configure a
|
13044
|
+
transformation and adapt the corresponding value, based on the config:
|
13045
|
+
|
13046
|
+
```app/models/post.js
|
13047
|
+
export default DS.Model.extend({
|
13048
|
+
text: DS.attr('text', {
|
13049
|
+
uppercase: true
|
13050
|
+
})
|
13051
|
+
});
|
13052
|
+
```
|
13053
|
+
|
13054
|
+
```app/transforms/text.js
|
13055
|
+
export default DS.Transform.extend({
|
13056
|
+
serialize: function(value, options) {
|
13057
|
+
if (options.uppercase) {
|
13058
|
+
return value.toUpperCase();
|
13059
|
+
}
|
13060
|
+
|
13061
|
+
return value;
|
13062
|
+
},
|
13063
|
+
|
13064
|
+
deserialize: function(value) {
|
13065
|
+
return value;
|
13066
|
+
}
|
13067
|
+
})
|
13068
|
+
```
|
13069
|
+
|
13072
13070
|
@namespace
|
13073
13071
|
@method attr
|
13074
13072
|
@for DS
|
@@ -13128,40 +13126,9 @@ define('ember-data/attr', ['exports', 'ember', 'ember-data/-private/debug'], fun
|
|
13128
13126
|
}
|
13129
13127
|
}).meta(meta);
|
13130
13128
|
}
|
13131
|
-
|
13132
|
-
// TODO add to documentation of `attr` function above, once this feature is added
|
13133
|
-
// /**
|
13134
|
-
// * The `options` hash is passed as second argument to a transforms'
|
13135
|
-
// * `serialize` and `deserialize` method. This allows to configure a
|
13136
|
-
// * transformation and adapt the corresponding value, based on the config:
|
13137
|
-
// *
|
13138
|
-
// * ```app/models/post.js
|
13139
|
-
// * export default DS.Model.extend({
|
13140
|
-
// * text: DS.attr('text', {
|
13141
|
-
// * uppercase: true
|
13142
|
-
// * })
|
13143
|
-
// * });
|
13144
|
-
// * ```
|
13145
|
-
// *
|
13146
|
-
// * ```app/transforms/text.js
|
13147
|
-
// * export default DS.Transform.extend({
|
13148
|
-
// * serialize: function(value, options) {
|
13149
|
-
// * if (options.uppercase) {
|
13150
|
-
// * return value.toUpperCase();
|
13151
|
-
// * }
|
13152
|
-
// *
|
13153
|
-
// * return value;
|
13154
|
-
// * },
|
13155
|
-
// *
|
13156
|
-
// * deserialize: function(value) {
|
13157
|
-
// * return value;
|
13158
|
-
// * }
|
13159
|
-
// * })
|
13160
|
-
// * ```
|
13161
|
-
// *
|
13162
|
-
// */
|
13163
13129
|
});
|
13164
|
-
define("ember-data", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/features", "ember-data/-private/core", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/model/internal-model", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/store", "ember-data/-private/system/model", "ember-data/model", "ember-data/-private/system/snapshot", "ember-data/adapter", "ember-data/serializer", "ember-data/-private/system/debug", "ember-data/adapters/errors", "ember-data/-private/system/record-arrays", "ember-data/-private/system/many-array", "ember-data/-private/system/record-array-manager", "ember-data/-private/adapters", "ember-data/-private/adapters/build-url-mixin", "ember-data/-private/serializers", "ember-inflector", "ember-data/serializers/embedded-records-mixin", "ember-data/-private/transforms", "ember-data/relationships", "ember-data/setup-container", "ember-data/-private/instance-initializers/initialize-store-service", "ember-data/-private/system/container-proxy", "ember-data/-private/system/relationships/state/relationship"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateFeatures, _emberDataPrivateCore, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateSystemModelInternalModel, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemStore, _emberDataPrivateSystemModel, _emberDataModel, _emberDataPrivateSystemSnapshot, _emberDataAdapter, _emberDataSerializer, _emberDataPrivateSystemDebug, _emberDataAdaptersErrors, _emberDataPrivateSystemRecordArrays, _emberDataPrivateSystemManyArray, _emberDataPrivateSystemRecordArrayManager, _emberDataPrivateAdapters, _emberDataPrivateAdaptersBuildUrlMixin, _emberDataPrivateSerializers, _emberInflector, _emberDataSerializersEmbeddedRecordsMixin, _emberDataPrivateTransforms, _emberDataRelationships, _emberDataSetupContainer, _emberDataPrivateInstanceInitializersInitializeStoreService, _emberDataPrivateSystemContainerProxy, _emberDataPrivateSystemRelationshipsStateRelationship) {
|
13130
|
+
define("ember-data", ["exports", "ember", "ember-data/-private/debug", "ember-data/-private/features", "ember-data/-private/global", "ember-data/-private/core", "ember-data/-private/system/normalize-model-name", "ember-data/-private/system/model/internal-model", "ember-data/-private/system/promise-proxies", "ember-data/-private/system/store", "ember-data/-private/system/model", "ember-data/model", "ember-data/-private/system/snapshot", "ember-data/adapter", "ember-data/serializer", "ember-data/-private/system/debug", "ember-data/adapters/errors", "ember-data/-private/system/record-arrays", "ember-data/-private/system/many-array", "ember-data/-private/system/record-array-manager", "ember-data/-private/adapters", "ember-data/-private/adapters/build-url-mixin", "ember-data/-private/serializers", "ember-inflector", "ember-data/serializers/embedded-records-mixin", "ember-data/-private/transforms", "ember-data/relationships", "ember-data/setup-container", "ember-data/-private/instance-initializers/initialize-store-service", "ember-data/-private/system/container-proxy", "ember-data/-private/system/relationships/state/relationship"], function (exports, _ember, _emberDataPrivateDebug, _emberDataPrivateFeatures, _emberDataPrivateGlobal, _emberDataPrivateCore, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateSystemModelInternalModel, _emberDataPrivateSystemPromiseProxies, _emberDataPrivateSystemStore, _emberDataPrivateSystemModel, _emberDataModel, _emberDataPrivateSystemSnapshot, _emberDataAdapter, _emberDataSerializer, _emberDataPrivateSystemDebug, _emberDataAdaptersErrors, _emberDataPrivateSystemRecordArrays, _emberDataPrivateSystemManyArray, _emberDataPrivateSystemRecordArrayManager, _emberDataPrivateAdapters, _emberDataPrivateAdaptersBuildUrlMixin, _emberDataPrivateSerializers, _emberInflector, _emberDataSerializersEmbeddedRecordsMixin, _emberDataPrivateTransforms, _emberDataRelationships, _emberDataSetupContainer, _emberDataPrivateInstanceInitializersInitializeStoreService, _emberDataPrivateSystemContainerProxy, _emberDataPrivateSystemRelationshipsStateRelationship) {
|
13131
|
+
|
13165
13132
|
/**
|
13166
13133
|
Ember Data
|
13167
13134
|
@module ember-data
|
@@ -13193,14 +13160,6 @@ define("ember-data", ["exports", "ember", "ember-data/-private/debug", "ember-da
|
|
13193
13160
|
_emberDataPrivateCore.default.TimeoutError = _emberDataAdaptersErrors.TimeoutError;
|
13194
13161
|
_emberDataPrivateCore.default.AbortError = _emberDataAdaptersErrors.AbortError;
|
13195
13162
|
|
13196
|
-
if (false) {
|
13197
|
-
_emberDataPrivateCore.default.UnauthorizedError = _emberDataAdaptersErrors.UnauthorizedError;
|
13198
|
-
_emberDataPrivateCore.default.ForbiddenError = _emberDataAdaptersErrors.ForbiddenError;
|
13199
|
-
_emberDataPrivateCore.default.NotFoundError = _emberDataAdaptersErrors.NotFoundError;
|
13200
|
-
_emberDataPrivateCore.default.ConflictError = _emberDataAdaptersErrors.ConflictError;
|
13201
|
-
_emberDataPrivateCore.default.ServerError = _emberDataAdaptersErrors.ServerError;
|
13202
|
-
}
|
13203
|
-
|
13204
13163
|
_emberDataPrivateCore.default.errorsHashToArray = _emberDataAdaptersErrors.errorsHashToArray;
|
13205
13164
|
_emberDataPrivateCore.default.errorsArrayToHash = _emberDataAdaptersErrors.errorsArrayToHash;
|
13206
13165
|
|
@@ -13249,7 +13208,14 @@ define("ember-data", ["exports", "ember", "ember-data/-private/debug", "ember-da
|
|
13249
13208
|
value: _emberDataPrivateSystemNormalizeModelName.default
|
13250
13209
|
});
|
13251
13210
|
|
13252
|
-
|
13211
|
+
Object.defineProperty(_emberDataPrivateGlobal.default, 'DS', {
|
13212
|
+
configurable: true,
|
13213
|
+
get: function () {
|
13214
|
+
(0, _emberDataPrivateDebug.deprecate)('Using the global version of DS is deprecated. Please either import ' + 'the specific modules needed or `import DS from \'ember-data\';`.', false, { id: 'ember-data.global-ds', until: '3.0.0' });
|
13215
|
+
|
13216
|
+
return _emberDataPrivateCore.default;
|
13217
|
+
}
|
13218
|
+
});
|
13253
13219
|
|
13254
13220
|
exports.default = _emberDataPrivateCore.default;
|
13255
13221
|
});
|
@@ -13691,10 +13657,8 @@ define('ember-data/serializers/embedded-records-mixin', ['exports', 'ember', 'em
|
|
13691
13657
|
} else if (this.hasSerializeRecordsOption(attr)) {
|
13692
13658
|
this._serializeEmbeddedHasMany(snapshot, json, relationship);
|
13693
13659
|
} else {
|
13694
|
-
if (
|
13695
|
-
|
13696
|
-
this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
|
13697
|
-
}
|
13660
|
+
if (this.hasSerializeIdsAndTypesOption(attr)) {
|
13661
|
+
this._serializeHasManyAsIdsAndTypes(snapshot, json, relationship);
|
13698
13662
|
}
|
13699
13663
|
}
|
13700
13664
|
},
|
@@ -14060,6 +14024,7 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14060
14024
|
_normalizeRelationshipDataHelper: function (relationshipDataHash) {
|
14061
14025
|
var type = this.modelNameFromPayloadKey(relationshipDataHash.type);
|
14062
14026
|
relationshipDataHash.type = type;
|
14027
|
+
|
14063
14028
|
return relationshipDataHash;
|
14064
14029
|
},
|
14065
14030
|
|
@@ -14074,10 +14039,14 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14074
14039
|
id: 'ds.serializer.type-is-undefined'
|
14075
14040
|
});
|
14076
14041
|
|
14077
|
-
var modelName =
|
14042
|
+
var modelName = undefined,
|
14043
|
+
usedLookup = undefined;
|
14044
|
+
|
14045
|
+
modelName = this.modelNameFromPayloadKey(resourceHash.type);
|
14046
|
+
usedLookup = 'modelNameFromPayloadKey';
|
14078
14047
|
|
14079
14048
|
if (!this.store._hasModelFor(modelName)) {
|
14080
|
-
(0, _emberDataPrivateDebug.warn)(this.warnMessageNoModelForType(modelName, resourceHash.type), false, {
|
14049
|
+
(0, _emberDataPrivateDebug.warn)(this.warnMessageNoModelForType(modelName, resourceHash.type, usedLookup), false, {
|
14081
14050
|
id: 'ds.serializer.model-for-type-missing'
|
14082
14051
|
});
|
14083
14052
|
return null;
|
@@ -14100,11 +14069,8 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14100
14069
|
*/
|
14101
14070
|
pushPayload: function (store, payload) {
|
14102
14071
|
var normalizedPayload = this._normalizeDocumentHelper(payload);
|
14103
|
-
|
14104
|
-
|
14105
|
-
} else {
|
14106
|
-
store.push(normalizedPayload);
|
14107
|
-
}
|
14072
|
+
|
14073
|
+
store.push(normalizedPayload);
|
14108
14074
|
},
|
14109
14075
|
|
14110
14076
|
/**
|
@@ -14147,7 +14113,7 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14147
14113
|
if (resourceHash.attributes) {
|
14148
14114
|
modelClass.eachAttribute(function (key) {
|
14149
14115
|
var attributeKey = _this.keyForAttribute(key, 'deserialize');
|
14150
|
-
if (resourceHash.attributes
|
14116
|
+
if (resourceHash.attributes[attributeKey] !== undefined) {
|
14151
14117
|
attributes[key] = resourceHash.attributes[attributeKey];
|
14152
14118
|
}
|
14153
14119
|
});
|
@@ -14195,7 +14161,7 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14195
14161
|
if (resourceHash.relationships) {
|
14196
14162
|
modelClass.eachRelationship(function (key, relationshipMeta) {
|
14197
14163
|
var relationshipKey = _this2.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
|
14198
|
-
if (resourceHash.relationships
|
14164
|
+
if (resourceHash.relationships[relationshipKey] !== undefined) {
|
14199
14165
|
|
14200
14166
|
var relationshipHash = resourceHash.relationships[relationshipKey];
|
14201
14167
|
relationships[key] = _this2.extractRelationship(relationshipHash);
|
@@ -14222,6 +14188,7 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14222
14188
|
@param {String} key
|
14223
14189
|
@return {String} the model's modelName
|
14224
14190
|
*/
|
14191
|
+
// TODO @deprecated Use modelNameFromPayloadType instead
|
14225
14192
|
modelNameFromPayloadKey: function (key) {
|
14226
14193
|
return (0, _emberInflector.singularize)((0, _emberDataPrivateSystemNormalizeModelName.default)(key));
|
14227
14194
|
},
|
@@ -14231,6 +14198,7 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14231
14198
|
@param {String} modelName
|
14232
14199
|
@return {String}
|
14233
14200
|
*/
|
14201
|
+
// TODO @deprecated Use payloadTypeFromModelName instead
|
14234
14202
|
payloadKeyFromModelName: function (modelName) {
|
14235
14203
|
return (0, _emberInflector.pluralize)(modelName);
|
14236
14204
|
},
|
@@ -14321,7 +14289,12 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14321
14289
|
*/
|
14322
14290
|
serialize: function (snapshot, options) {
|
14323
14291
|
var data = this._super.apply(this, arguments);
|
14324
|
-
|
14292
|
+
|
14293
|
+
var payloadType = undefined;
|
14294
|
+
|
14295
|
+
payloadType = this.payloadKeyFromModelName(snapshot.modelName);
|
14296
|
+
|
14297
|
+
data.type = payloadType;
|
14325
14298
|
return { data: data };
|
14326
14299
|
},
|
14327
14300
|
|
@@ -14341,7 +14314,7 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14341
14314
|
var value = snapshot.attr(key);
|
14342
14315
|
if (type) {
|
14343
14316
|
var transform = this.transformFor(type);
|
14344
|
-
value = transform.serialize(value
|
14317
|
+
value = transform.serialize(value);
|
14345
14318
|
}
|
14346
14319
|
|
14347
14320
|
var payloadKey = this._getMappedKey(key, snapshot.type);
|
@@ -14376,8 +14349,12 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14376
14349
|
|
14377
14350
|
var data = null;
|
14378
14351
|
if (belongsTo) {
|
14352
|
+
var payloadType = undefined;
|
14353
|
+
|
14354
|
+
payloadType = this.payloadKeyFromModelName(belongsTo.modelName);
|
14355
|
+
|
14379
14356
|
data = {
|
14380
|
-
type:
|
14357
|
+
type: payloadType,
|
14381
14358
|
id: belongsTo.id
|
14382
14359
|
};
|
14383
14360
|
}
|
@@ -14395,8 +14372,9 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14395
14372
|
*/
|
14396
14373
|
serializeHasMany: function (snapshot, json, relationship) {
|
14397
14374
|
var key = relationship.key;
|
14375
|
+
var shouldSerializeHasMany = '_shouldSerializeHasMany';
|
14398
14376
|
|
14399
|
-
if (this
|
14377
|
+
if (this[shouldSerializeHasMany](snapshot, key, relationship)) {
|
14400
14378
|
var hasMany = snapshot.hasMany(key);
|
14401
14379
|
if (hasMany !== undefined) {
|
14402
14380
|
|
@@ -14411,8 +14389,13 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14411
14389
|
|
14412
14390
|
for (var i = 0; i < hasMany.length; i++) {
|
14413
14391
|
var item = hasMany[i];
|
14392
|
+
|
14393
|
+
var payloadType = undefined;
|
14394
|
+
|
14395
|
+
payloadType = this.payloadKeyFromModelName(item.modelName);
|
14396
|
+
|
14414
14397
|
data[i] = {
|
14415
|
-
type:
|
14398
|
+
type: payloadType,
|
14416
14399
|
id: item.id
|
14417
14400
|
};
|
14418
14401
|
}
|
@@ -14433,8 +14416,8 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14433
14416
|
warnMessageForUndefinedType: function () {
|
14434
14417
|
return 'Encountered a resource object with an undefined type (resolved resource using ' + this.constructor.toString() + ')';
|
14435
14418
|
},
|
14436
|
-
warnMessageNoModelForType: function (modelName, originalType) {
|
14437
|
-
return 'Encountered a resource object with type "' + originalType + '", but no model was found for model name "' + modelName + '" (resolved model name using ' + this.constructor.toString() + '.
|
14419
|
+
warnMessageNoModelForType: function (modelName, originalType, usedLookup) {
|
14420
|
+
return 'Encountered a resource object with type "' + originalType + '", but no model was found for model name "' + modelName + '" (resolved model name using \'' + this.constructor.toString() + '.' + usedLookup + '("' + originalType + '")).';
|
14438
14421
|
}
|
14439
14422
|
});
|
14440
14423
|
});
|
@@ -14444,7 +14427,80 @@ define('ember-data/serializers/json-api', ['exports', 'ember', 'ember-data/-priv
|
|
14444
14427
|
/**
|
14445
14428
|
@module ember-data
|
14446
14429
|
*/
|
14447
|
-
|
14430
|
+
|
14431
|
+
/**
|
14432
|
+
`modelNameFromPayloadType` can be used to change the mapping for a DS model
|
14433
|
+
name, taken from the value in the payload.
|
14434
|
+
Say your API namespaces the type of a model and returns the following
|
14435
|
+
payload for the `post` model:
|
14436
|
+
```javascript
|
14437
|
+
// GET /api/posts/1
|
14438
|
+
{
|
14439
|
+
"data": {
|
14440
|
+
"id": 1,
|
14441
|
+
"type: "api::v1::post"
|
14442
|
+
}
|
14443
|
+
}
|
14444
|
+
```
|
14445
|
+
By overwriting `modelNameFromPayloadType` you can specify that the
|
14446
|
+
`posr` model should be used:
|
14447
|
+
```app/serializers/application.js
|
14448
|
+
import JSONAPISerializer from "ember-data/serializers/json-api";
|
14449
|
+
export default JSONAPISerializer.extend({
|
14450
|
+
modelNameFromPayloadType(payloadType) {
|
14451
|
+
return payloadType.replace('api::v1::', '');
|
14452
|
+
}
|
14453
|
+
});
|
14454
|
+
```
|
14455
|
+
By default the modelName for a model is its singularized name in dasherized
|
14456
|
+
form. Usually, Ember Data can use the correct inflection to do this for
|
14457
|
+
you. Most of the time, you won't need to override
|
14458
|
+
`modelNameFromPayloadType` for this purpose.
|
14459
|
+
Also take a look at
|
14460
|
+
[payloadTypeFromModelName](#method_payloadTypeFromModelName) to customize
|
14461
|
+
how the type of a record should be serialized.
|
14462
|
+
@method modelNameFromPayloadType
|
14463
|
+
@public
|
14464
|
+
@param {String} payloadType type from payload
|
14465
|
+
@return {String} modelName
|
14466
|
+
*/
|
14467
|
+
|
14468
|
+
/**
|
14469
|
+
`payloadTypeFromModelName` can be used to change the mapping for the type in
|
14470
|
+
the payload, taken from the model name.
|
14471
|
+
Say your API namespaces the type of a model and expects the following
|
14472
|
+
payload when you update the `post` model:
|
14473
|
+
```javascript
|
14474
|
+
// POST /api/posts/1
|
14475
|
+
{
|
14476
|
+
"data": {
|
14477
|
+
"id": 1,
|
14478
|
+
"type": "api::v1::post"
|
14479
|
+
}
|
14480
|
+
}
|
14481
|
+
```
|
14482
|
+
By overwriting `payloadTypeFromModelName` you can specify that the
|
14483
|
+
namespaces model name for the `post` should be used:
|
14484
|
+
```app/serializers/application.js
|
14485
|
+
import JSONAPISerializer from "ember-data/serializers/json-api";
|
14486
|
+
export default JSONAPISerializer.extend({
|
14487
|
+
payloadTypeFromModelName(modelName) {
|
14488
|
+
return "api::v1::" + modelName;
|
14489
|
+
}
|
14490
|
+
});
|
14491
|
+
```
|
14492
|
+
By default the payload type is the pluralized model name. Usually, Ember
|
14493
|
+
Data can use the correct inflection to do this for you. Most of the time,
|
14494
|
+
you won't need to override `payloadTypeFromModelName` for this purpose.
|
14495
|
+
Also take a look at
|
14496
|
+
[modelNameFromPayloadType](#method_modelNameFromPayloadType) to customize
|
14497
|
+
how the model name from should be mapped from the payload.
|
14498
|
+
@method payloadTypeFromModelName
|
14499
|
+
@public
|
14500
|
+
@param {String} modelname modelName from the record
|
14501
|
+
@return {String} payloadType
|
14502
|
+
*/
|
14503
|
+
define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/debug', 'ember-data/serializer', 'ember-data/-private/system/coerce-id', 'ember-data/-private/system/normalize-model-name', 'ember-data/-private/utils', 'ember-data/-private/features', 'ember-data/adapters/errors'], function (exports, _ember, _emberDataPrivateDebug, _emberDataSerializer, _emberDataPrivateSystemCoerceId, _emberDataPrivateSystemNormalizeModelName, _emberDataPrivateUtils, _emberDataPrivateFeatures, _emberDataAdaptersErrors) {
|
14448
14504
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
14449
14505
|
|
14450
14506
|
var get = _ember.default.get;
|
@@ -14517,7 +14573,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
14517
14573
|
@namespace DS
|
14518
14574
|
@extends DS.Serializer
|
14519
14575
|
*/
|
14520
|
-
|
14576
|
+
var JSONSerializer = _emberDataSerializer.default.extend({
|
14521
14577
|
|
14522
14578
|
/**
|
14523
14579
|
The `primaryKey` is used when serializing and deserializing
|
@@ -14605,23 +14661,16 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
14605
14661
|
applyTransforms: function (typeClass, data) {
|
14606
14662
|
var _this = this;
|
14607
14663
|
|
14608
|
-
var attributes =
|
14609
|
-
if (true) {
|
14610
|
-
attributes = get(typeClass, 'attributes');
|
14611
|
-
}
|
14664
|
+
var attributes = get(typeClass, 'attributes');
|
14612
14665
|
|
14613
14666
|
typeClass.eachTransformedAttribute(function (key, typeClass) {
|
14614
|
-
if (
|
14667
|
+
if (data[key] === undefined) {
|
14615
14668
|
return;
|
14616
14669
|
}
|
14617
14670
|
|
14618
14671
|
var transform = _this.transformFor(typeClass);
|
14619
|
-
|
14620
|
-
|
14621
|
-
data[key] = transform.deserialize(data[key], transformMeta.options);
|
14622
|
-
} else {
|
14623
|
-
data[key] = transform.deserialize(data[key]);
|
14624
|
-
}
|
14672
|
+
var transformMeta = attributes.get(key);
|
14673
|
+
data[key] = transform.deserialize(data[key], transformMeta.options);
|
14625
14674
|
});
|
14626
14675
|
|
14627
14676
|
return data;
|
@@ -14986,7 +15035,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
14986
15035
|
|
14987
15036
|
modelClass.eachAttribute(function (key) {
|
14988
15037
|
attributeKey = _this2.keyForAttribute(key, 'deserialize');
|
14989
|
-
if (resourceHash
|
15038
|
+
if (resourceHash[attributeKey] !== undefined) {
|
14990
15039
|
attributes[key] = resourceHash[attributeKey];
|
14991
15040
|
}
|
14992
15041
|
});
|
@@ -15061,7 +15110,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15061
15110
|
modelClass.eachRelationship(function (key, relationshipMeta) {
|
15062
15111
|
var relationship = null;
|
15063
15112
|
var relationshipKey = _this3.keyForRelationship(key, relationshipMeta.kind, 'deserialize');
|
15064
|
-
if (resourceHash
|
15113
|
+
if (resourceHash[relationshipKey] !== undefined) {
|
15065
15114
|
var data = null;
|
15066
15115
|
var relationshipHash = resourceHash[relationshipKey];
|
15067
15116
|
if (relationshipMeta.kind === 'belongsTo') {
|
@@ -15087,7 +15136,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15087
15136
|
}
|
15088
15137
|
|
15089
15138
|
var linkKey = _this3.keyForLink(key, relationshipMeta.kind);
|
15090
|
-
if (resourceHash.links && resourceHash.links
|
15139
|
+
if (resourceHash.links && resourceHash.links[linkKey] !== undefined) {
|
15091
15140
|
var related = resourceHash.links[linkKey];
|
15092
15141
|
relationship = relationship || {};
|
15093
15142
|
relationship.links = { related: related };
|
@@ -15106,6 +15155,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15106
15155
|
@param {String} key
|
15107
15156
|
@return {String} the model's modelName
|
15108
15157
|
*/
|
15158
|
+
// TODO @deprecated Use modelNameFromPayloadType instead
|
15109
15159
|
modelNameFromPayloadKey: function (key) {
|
15110
15160
|
return (0, _emberDataPrivateSystemNormalizeModelName.default)(key);
|
15111
15161
|
},
|
@@ -15125,7 +15175,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15125
15175
|
if (key === payloadKey) {
|
15126
15176
|
return;
|
15127
15177
|
}
|
15128
|
-
if (
|
15178
|
+
if (hash[payloadKey] === undefined) {
|
15129
15179
|
return;
|
15130
15180
|
}
|
15131
15181
|
|
@@ -15150,7 +15200,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15150
15200
|
if (key === payloadKey) {
|
15151
15201
|
return;
|
15152
15202
|
}
|
15153
|
-
if (
|
15203
|
+
if (hash[payloadKey] === undefined) {
|
15154
15204
|
return;
|
15155
15205
|
}
|
15156
15206
|
|
@@ -15172,7 +15222,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15172
15222
|
for (key in attrs) {
|
15173
15223
|
normalizedKey = payloadKey = this._getMappedKey(key, modelClass);
|
15174
15224
|
|
15175
|
-
if (
|
15225
|
+
if (hash[payloadKey] === undefined) {
|
15176
15226
|
continue;
|
15177
15227
|
}
|
15178
15228
|
|
@@ -15251,6 +15301,26 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15251
15301
|
return attrs && attrs[key] && attrs[key].serialize === true;
|
15252
15302
|
},
|
15253
15303
|
|
15304
|
+
/**
|
15305
|
+
Check if the given hasMany relationship should be serialized
|
15306
|
+
@method shouldSerializeHasMany
|
15307
|
+
@param {DS.Snapshot} snapshot
|
15308
|
+
@param {String} key
|
15309
|
+
@param {String} relationshipType
|
15310
|
+
@return {boolean} true if the hasMany relationship should be serialized
|
15311
|
+
*/
|
15312
|
+
|
15313
|
+
shouldSerializeHasMany: function (snapshot, key, relationship) {
|
15314
|
+
if (this._shouldSerializeHasMany !== JSONSerializer.prototype._shouldSerializeHasMany) {
|
15315
|
+
(0, _emberDataPrivateDebug.deprecate)('The private method _shouldSerializeHasMany has been promoted to the public API. Please remove the underscore to use the public shouldSerializeHasMany method.', false, {
|
15316
|
+
id: 'ds.serializer.private-should-serialize-has-many',
|
15317
|
+
until: '3.0.0'
|
15318
|
+
});
|
15319
|
+
}
|
15320
|
+
|
15321
|
+
return this._shouldSerializeHasMany(snapshot, key, relationship);
|
15322
|
+
},
|
15323
|
+
|
15254
15324
|
/**
|
15255
15325
|
Check if the given hasMany relationship should be serialized
|
15256
15326
|
@method _shouldSerializeHasMany
|
@@ -15465,11 +15535,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15465
15535
|
var value = snapshot.attr(key);
|
15466
15536
|
if (type) {
|
15467
15537
|
var transform = this.transformFor(type);
|
15468
|
-
|
15469
|
-
value = transform.serialize(value, attribute.options);
|
15470
|
-
} else {
|
15471
|
-
value = transform.serialize(value);
|
15472
|
-
}
|
15538
|
+
value = transform.serialize(value, attribute.options);
|
15473
15539
|
}
|
15474
15540
|
|
15475
15541
|
// if provided, use the mapping provided by `attrs` in
|
@@ -15554,8 +15620,9 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15554
15620
|
*/
|
15555
15621
|
serializeHasMany: function (snapshot, json, relationship) {
|
15556
15622
|
var key = relationship.key;
|
15623
|
+
var shouldSerializeHasMany = '_shouldSerializeHasMany';
|
15557
15624
|
|
15558
|
-
if (this
|
15625
|
+
if (this[shouldSerializeHasMany](snapshot, key, relationship)) {
|
15559
15626
|
var hasMany = snapshot.hasMany(key, { ids: true });
|
15560
15627
|
if (hasMany !== undefined) {
|
15561
15628
|
// if provided, use the mapping provided by `attrs` in
|
@@ -15622,7 +15689,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15622
15689
|
@param {Object} payload
|
15623
15690
|
*/
|
15624
15691
|
extractMeta: function (store, modelClass, payload) {
|
15625
|
-
if (payload && payload
|
15692
|
+
if (payload && payload['meta'] !== undefined) {
|
15626
15693
|
var meta = payload.meta;
|
15627
15694
|
delete payload.meta;
|
15628
15695
|
return meta;
|
@@ -15712,7 +15779,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15712
15779
|
|
15713
15780
|
typeClass.eachAttribute(function (name) {
|
15714
15781
|
var key = _this7.keyForAttribute(name, 'deserialize');
|
15715
|
-
if (key !== name && payload
|
15782
|
+
if (key !== name && payload[key] !== undefined) {
|
15716
15783
|
payload[name] = payload[key];
|
15717
15784
|
delete payload[key];
|
15718
15785
|
}
|
@@ -15720,7 +15787,7 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15720
15787
|
|
15721
15788
|
typeClass.eachRelationship(function (name) {
|
15722
15789
|
var key = _this7.keyForRelationship(name, 'deserialize');
|
15723
|
-
if (key !== name && payload
|
15790
|
+
if (key !== name && payload[key] !== undefined) {
|
15724
15791
|
payload[name] = payload[key];
|
15725
15792
|
delete payload[key];
|
15726
15793
|
}
|
@@ -15803,7 +15870,16 @@ define('ember-data/serializers/json', ['exports', 'ember', 'ember-data/-private/
|
|
15803
15870
|
return transform;
|
15804
15871
|
}
|
15805
15872
|
});
|
15873
|
+
|
15874
|
+
exports.default = JSONSerializer;
|
15806
15875
|
});
|
15876
|
+
|
15877
|
+
/**
|
15878
|
+
@method modelNameFromPayloadType
|
15879
|
+
@public
|
15880
|
+
@param {String} type
|
15881
|
+
@return {String} the model's modelName
|
15882
|
+
*/
|
15807
15883
|
define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/debug", "ember-data/serializers/json", "ember-data/-private/system/normalize-model-name", "ember-inflector", "ember-data/-private/system/coerce-id", "ember-data/-private/utils", "ember-data/-private/features"], function (exports, _ember, _emberDataPrivateDebug, _emberDataSerializersJson, _emberDataPrivateSystemNormalizeModelName, _emberInflector, _emberDataPrivateSystemCoerceId, _emberDataPrivateUtils, _emberDataPrivateFeatures) {
|
15808
15884
|
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
15809
15885
|
|
@@ -15908,7 +15984,7 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
15908
15984
|
* With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }`
|
15909
15985
|
* With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }`
|
15910
15986
|
You can use this method, for example, to normalize underscored keys to camelized
|
15911
|
-
or other general-purpose normalizations. You will only need to implement
|
15987
|
+
or other general-purpose normalizations. You will only need to implement
|
15912
15988
|
`normalize` and manipulate the payload as desired.
|
15913
15989
|
For example, if the `IDs` under `"comments"` are provided as `_id` instead of
|
15914
15990
|
`id`, you can specify how to normalize just the comments:
|
@@ -15918,14 +15994,14 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
15918
15994
|
normalize(model, hash, prop) {
|
15919
15995
|
if (prop === 'comments') {
|
15920
15996
|
hash.id = hash._id;
|
15921
|
-
delete hash._id;
|
15997
|
+
delete hash._id;
|
15922
15998
|
}
|
15923
15999
|
return this._super(...arguments);
|
15924
16000
|
}
|
15925
16001
|
});
|
15926
16002
|
```
|
15927
|
-
On each call to the `normalize` method, the third parameter (`prop`) is always
|
15928
|
-
one of the keys that were in the original payload or in the result of another
|
16003
|
+
On each call to the `normalize` method, the third parameter (`prop`) is always
|
16004
|
+
one of the keys that were in the original payload or in the result of another
|
15929
16005
|
normalization as `normalizeResponse`.
|
15930
16006
|
@method normalize
|
15931
16007
|
@param {DS.Model} modelClass
|
@@ -15966,7 +16042,6 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
15966
16042
|
var modelClass = store.modelFor(modelName);
|
15967
16043
|
var serializer = store.serializerFor(modelName);
|
15968
16044
|
|
15969
|
-
/*jshint loopfunc:true*/
|
15970
16045
|
_ember.default.makeArray(arrayHash).forEach(function (hash) {
|
15971
16046
|
var _normalizePolymorphicRecord = _this._normalizePolymorphicRecord(store, hash, prop, modelClass, serializer);
|
15972
16047
|
|
@@ -15985,17 +16060,23 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
15985
16060
|
},
|
15986
16061
|
|
15987
16062
|
_normalizePolymorphicRecord: function (store, hash, prop, primaryModelClass, primarySerializer) {
|
15988
|
-
var serializer =
|
15989
|
-
|
16063
|
+
var serializer = primarySerializer;
|
16064
|
+
var modelClass = primaryModelClass;
|
16065
|
+
|
15990
16066
|
var primaryHasTypeAttribute = (0, _emberDataPrivateUtils.modelHasAttributeOrRelationshipNamedType)(primaryModelClass);
|
15991
|
-
|
15992
|
-
if (!primaryHasTypeAttribute && hash.type
|
15993
|
-
|
15994
|
-
|
15995
|
-
|
15996
|
-
|
15997
|
-
|
16067
|
+
|
16068
|
+
if (!primaryHasTypeAttribute && hash.type) {
|
16069
|
+
// Support polymorphic records in async relationships
|
16070
|
+
var modelName = undefined;
|
16071
|
+
|
16072
|
+
modelName = this.modelNameFromPayloadKey(hash.type);
|
16073
|
+
|
16074
|
+
if (store._hasModelFor(modelName)) {
|
16075
|
+
serializer = store.serializerFor(modelName);
|
16076
|
+
modelClass = store.modelFor(modelName);
|
16077
|
+
}
|
15998
16078
|
}
|
16079
|
+
|
15999
16080
|
return serializer.normalize(modelClass, hash, prop);
|
16000
16081
|
},
|
16001
16082
|
|
@@ -16112,7 +16193,6 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
16112
16193
|
}
|
16113
16194
|
|
16114
16195
|
if (isSingle) {
|
16115
|
-
/*jshint loopfunc:true*/
|
16116
16196
|
data.forEach(function (resource) {
|
16117
16197
|
|
16118
16198
|
/*
|
@@ -16197,7 +16277,6 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
16197
16277
|
var type = store.modelFor(modelName);
|
16198
16278
|
var typeSerializer = store.serializerFor(type.modelName);
|
16199
16279
|
|
16200
|
-
/*jshint loopfunc:true*/
|
16201
16280
|
_ember.default.makeArray(payload[prop]).forEach(function (hash) {
|
16202
16281
|
var _typeSerializer$normalize = typeSerializer.normalize(type, hash, prop);
|
16203
16282
|
|
@@ -16213,11 +16292,7 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
16213
16292
|
});
|
16214
16293
|
}
|
16215
16294
|
|
16216
|
-
|
16217
|
-
return store.push(documentHash);
|
16218
|
-
} else {
|
16219
|
-
store.push(documentHash);
|
16220
|
-
}
|
16295
|
+
store.push(documentHash);
|
16221
16296
|
},
|
16222
16297
|
|
16223
16298
|
/**
|
@@ -16530,7 +16605,8 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
16530
16605
|
var isPolymorphic = relationshipMeta.options.polymorphic;
|
16531
16606
|
var typeProperty = this.keyForPolymorphicType(key, relationshipType, 'deserialize');
|
16532
16607
|
|
16533
|
-
if (isPolymorphic && resourceHash
|
16608
|
+
if (isPolymorphic && resourceHash[typeProperty] !== undefined && typeof relationshipHash !== 'object') {
|
16609
|
+
|
16534
16610
|
var type = this.modelNameFromPayloadKey(resourceHash[typeProperty]);
|
16535
16611
|
return {
|
16536
16612
|
id: relationshipHash,
|
@@ -16555,6 +16631,82 @@ define("ember-data/serializers/rest", ["exports", "ember", "ember-data/-private/
|
|
16555
16631
|
/**
|
16556
16632
|
@module ember-data
|
16557
16633
|
*/
|
16634
|
+
|
16635
|
+
/**
|
16636
|
+
`modelNameFromPayloadType` can be used to change the mapping for a DS model
|
16637
|
+
name, taken from the value in the payload.
|
16638
|
+
Say your API namespaces the type of a model and returns the following
|
16639
|
+
payload for the `post` model, which has a polymorphic `user` relationship:
|
16640
|
+
```javascript
|
16641
|
+
// GET /api/posts/1
|
16642
|
+
{
|
16643
|
+
"post": {
|
16644
|
+
"id": 1,
|
16645
|
+
"user": 1,
|
16646
|
+
"userType: "api::v1::administrator"
|
16647
|
+
}
|
16648
|
+
}
|
16649
|
+
```
|
16650
|
+
By overwriting `modelNameFromPayloadType` you can specify that the
|
16651
|
+
`administrator` model should be used:
|
16652
|
+
```app/serializers/application.js
|
16653
|
+
import RESTSerializer from "ember-data/serializers/rest";
|
16654
|
+
export default RESTSerializer.extend({
|
16655
|
+
modelNameFromPayloadType(payloadType) {
|
16656
|
+
return payloadType.replace('api::v1::', '');
|
16657
|
+
}
|
16658
|
+
});
|
16659
|
+
```
|
16660
|
+
By default the modelName for a model is its name in dasherized form.
|
16661
|
+
Usually, Ember Data can use the correct inflection to do this for you. Most
|
16662
|
+
of the time, you won't need to override `modelNameFromPayloadType` for this
|
16663
|
+
purpose.
|
16664
|
+
Also take a look at
|
16665
|
+
[payloadTypeFromModelName](#method_payloadTypeFromModelName) to customize
|
16666
|
+
how the type of a record should be serialized.
|
16667
|
+
@method modelNameFromPayloadType
|
16668
|
+
@public
|
16669
|
+
@param {String} payloadType type from payload
|
16670
|
+
@return {String} modelName
|
16671
|
+
*/
|
16672
|
+
|
16673
|
+
/**
|
16674
|
+
`payloadTypeFromModelName` can be used to change the mapping for the type in
|
16675
|
+
the payload, taken from the model name.
|
16676
|
+
Say your API namespaces the type of a model and expects the following
|
16677
|
+
payload when you update the `post` model, which has a polymorphic `user`
|
16678
|
+
relationship:
|
16679
|
+
```javascript
|
16680
|
+
// POST /api/posts/1
|
16681
|
+
{
|
16682
|
+
"post": {
|
16683
|
+
"id": 1,
|
16684
|
+
"user": 1,
|
16685
|
+
"userType": "api::v1::administrator"
|
16686
|
+
}
|
16687
|
+
}
|
16688
|
+
```
|
16689
|
+
By overwriting `payloadTypeFromModelName` you can specify that the
|
16690
|
+
namespaces model name for the `administrator` should be used:
|
16691
|
+
```app/serializers/application.js
|
16692
|
+
import RESTSerializer from "ember-data/serializers/rest";
|
16693
|
+
export default RESTSerializer.extend({
|
16694
|
+
payloadTypeFromModelName(modelName) {
|
16695
|
+
return "api::v1::" + modelName;
|
16696
|
+
}
|
16697
|
+
});
|
16698
|
+
```
|
16699
|
+
By default the payload type is the camelized model name. Usually, Ember
|
16700
|
+
Data can use the correct inflection to do this for you. Most of the time,
|
16701
|
+
you won't need to override `payloadTypeFromModelName` for this purpose.
|
16702
|
+
Also take a look at
|
16703
|
+
[modelNameFromPayloadType](#method_modelNameFromPayloadType) to customize
|
16704
|
+
how the model name from should be mapped from the payload.
|
16705
|
+
@method payloadTypeFromModelName
|
16706
|
+
@public
|
16707
|
+
@param {String} modelname modelName from the record
|
16708
|
+
@return {String} payloadType
|
16709
|
+
*/
|
16558
16710
|
define('ember-data/setup-container', ['exports', 'ember-data/-private/initializers/store', 'ember-data/-private/initializers/transforms', 'ember-data/-private/initializers/store-injections', 'ember-data/-private/initializers/data-adapter'], function (exports, _emberDataPrivateInitializersStore, _emberDataPrivateInitializersTransforms, _emberDataPrivateInitializersStoreInjections, _emberDataPrivateInitializersDataAdapter) {
|
16559
16711
|
exports.default = setupContainer;
|
16560
16712
|
|
@@ -16613,12 +16765,13 @@ define('ember-data/transform', ['exports', 'ember'], function (exports, _ember)
|
|
16613
16765
|
method must return the serialized value.
|
16614
16766
|
Example
|
16615
16767
|
```javascript
|
16616
|
-
serialize: function(deserialized) {
|
16768
|
+
serialize: function(deserialized, options) {
|
16617
16769
|
return Ember.isEmpty(deserialized) ? null : Number(deserialized);
|
16618
16770
|
}
|
16619
16771
|
```
|
16620
16772
|
@method serialize
|
16621
16773
|
@param deserialized The deserialized value
|
16774
|
+
@param options hash of options passed to `DS.attr`
|
16622
16775
|
@return The serialized value
|
16623
16776
|
*/
|
16624
16777
|
serialize: null,
|
@@ -16628,19 +16781,20 @@ define('ember-data/transform', ['exports', 'ember'], function (exports, _ember)
|
|
16628
16781
|
return the deserialized value for the record attribute.
|
16629
16782
|
Example
|
16630
16783
|
```javascript
|
16631
|
-
deserialize: function(serialized) {
|
16784
|
+
deserialize: function(serialized, options) {
|
16632
16785
|
return empty(serialized) ? null : Number(serialized);
|
16633
16786
|
}
|
16634
16787
|
```
|
16635
16788
|
@method deserialize
|
16636
16789
|
@param serialized The serialized value
|
16790
|
+
@param options hash of options passed to `DS.attr`
|
16637
16791
|
@return The deserialized value
|
16638
16792
|
*/
|
16639
16793
|
deserialize: null
|
16640
16794
|
});
|
16641
16795
|
});
|
16642
16796
|
define("ember-data/version", ["exports"], function (exports) {
|
16643
|
-
exports.default = "2.
|
16797
|
+
exports.default = "2.7.0-beta.1";
|
16644
16798
|
});
|
16645
16799
|
define("ember-inflector", ["exports", "ember", "ember-inflector/lib/system", "ember-inflector/lib/ext/string"], function (exports, _ember, _emberInflectorLibSystem, _emberInflectorLibExtString) {
|
16646
16800
|
|
@@ -17035,7 +17189,7 @@ define('ember-inflector/lib/system/inflector', ['exports', 'ember'], function (e
|
|
17035
17189
|
return word;
|
17036
17190
|
}
|
17037
17191
|
|
17038
|
-
for (rule in irregular) {
|
17192
|
+
for (rule in this.rules.irregular) {
|
17039
17193
|
if (lowercase.match(rule + "$")) {
|
17040
17194
|
substitution = irregular[rule];
|
17041
17195
|
|
@@ -17044,7 +17198,7 @@ define('ember-inflector/lib/system/inflector', ['exports', 'ember'], function (e
|
|
17044
17198
|
rule = capitalize(rule);
|
17045
17199
|
}
|
17046
17200
|
|
17047
|
-
return word.replace(
|
17201
|
+
return word.replace(rule, substitution);
|
17048
17202
|
}
|
17049
17203
|
}
|
17050
17204
|
|
@@ -17105,6 +17259,15 @@ define('ember', [], function() {
|
|
17105
17259
|
|
17106
17260
|
|
17107
17261
|
require("ember-data");
|
17262
|
+
;(function() {
|
17263
|
+
var global = require('ember-data/-private/global').default;
|
17264
|
+
var DS = require('ember-data').default;
|
17265
|
+
Object.defineProperty(global, 'DS', {
|
17266
|
+
get: function() {
|
17267
|
+
return DS;
|
17268
|
+
}
|
17269
|
+
});
|
17270
|
+
})();
|
17108
17271
|
})();
|
17109
17272
|
;(function() {
|
17110
17273
|
function processEmberDataShims() {
|
@@ -17144,6 +17307,8 @@ require("ember-data");
|
|
17144
17307
|
processEmberDataShims();
|
17145
17308
|
}
|
17146
17309
|
})();
|
17310
|
+
/* eslint no-extra-semi: "off" */
|
17311
|
+
|
17147
17312
|
;(function() {
|
17148
17313
|
/* globals Ember */
|
17149
17314
|
/* globals DS */
|