@@ -2373,6 +2373,7 @@ function destroy(resourceName, id, options) {
2373
2373
2374
2374
options = options || { } ;
2375
2375
2376
+ id = DS . utils . resolveId ( definition , id ) ;
2376
2377
if ( ! definition ) {
2377
2378
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
2378
2379
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -3095,6 +3096,7 @@ function refresh(resourceName, id, options) {
3095
3096
3096
3097
options = options || { } ;
3097
3098
3099
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
3098
3100
if ( ! DS . definitions [ resourceName ] ) {
3099
3101
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
3100
3102
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -3180,6 +3182,7 @@ function save(resourceName, id, options) {
3180
3182
3181
3183
options = options || { } ;
3182
3184
3185
+ id = DS . utils . resolveId ( definition , id ) ;
3183
3186
if ( ! definition ) {
3184
3187
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
3185
3188
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -3330,6 +3333,7 @@ function update(resourceName, id, attrs, options) {
3330
3333
3331
3334
options = options || { } ;
3332
3335
3336
+ id = DS . utils . resolveId ( definition , id ) ;
3333
3337
if ( ! definition ) {
3334
3338
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
3335
3339
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -4411,6 +4415,7 @@ function bindOne(scope, expr, resourceName, id, cb) {
4411
4415
var DS = this ;
4412
4416
var IA = DS . errors . IA ;
4413
4417
4418
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
4414
4419
if ( ! DS . utils . isObject ( scope ) ) {
4415
4420
throw new IA ( errorPrefix ( resourceName ) + 'scope: Must be an object!' ) ;
4416
4421
} else if ( ! DS . utils . isString ( expr ) ) {
@@ -4487,6 +4492,8 @@ function changeHistory(resourceName, id) {
4487
4492
var DSUtils = DS . utils ;
4488
4493
var definition = DS . definitions [ resourceName ] ;
4489
4494
var resource = DS . store [ resourceName ] ;
4495
+
4496
+ id = DS . utils . resolveId ( definition , id ) ;
4490
4497
if ( resourceName && ! DS . definitions [ resourceName ] ) {
4491
4498
throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
4492
4499
} else if ( id && ! DSUtils . isString ( id ) && ! DSUtils . isNumber ( id ) ) {
@@ -4551,6 +4558,8 @@ function errorPrefix(resourceName) {
4551
4558
*/
4552
4559
function changes ( resourceName , id ) {
4553
4560
var DS = this ;
4561
+
4562
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
4554
4563
if ( ! DS . definitions [ resourceName ] ) {
4555
4564
throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
4556
4565
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -4655,6 +4664,7 @@ function compute(resourceName, instance) {
4655
4664
var IA = DS . errors . IA ;
4656
4665
var definition = DS . definitions [ resourceName ] ;
4657
4666
4667
+ instance = DS . utils . resolveItem ( DS . store [ resourceName ] , instance ) ;
4658
4668
if ( ! definition ) {
4659
4669
throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
4660
4670
} else if ( ! DS . utils . isObject ( instance ) && ! DS . utils . isString ( instance ) && ! DS . utils . isNumber ( instance ) ) {
@@ -5211,6 +5221,8 @@ function _eject(definition, resource, id) {
5211
5221
function eject ( resourceName , id ) {
5212
5222
var DS = this ;
5213
5223
var definition = DS . definitions [ resourceName ] ;
5224
+
5225
+ id = DS . utils . resolveId ( definition , id ) ;
5214
5226
if ( ! definition ) {
5215
5227
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
5216
5228
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -5540,6 +5552,8 @@ function diffIsEmpty(utils, diff) {
5540
5552
*/
5541
5553
function hasChanges ( resourceName , id ) {
5542
5554
var DS = this ;
5555
+
5556
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
5543
5557
if ( ! DS . definitions [ resourceName ] ) {
5544
5558
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
5545
5559
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6127,6 +6141,8 @@ function errorPrefix(resourceName, id) {
6127
6141
function lastModified ( resourceName , id ) {
6128
6142
var DS = this ;
6129
6143
var resource = DS . store [ resourceName ] ;
6144
+
6145
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
6130
6146
if ( ! DS . definitions [ resourceName ] ) {
6131
6147
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
6132
6148
} else if ( id && ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6192,6 +6208,8 @@ function errorPrefix(resourceName, id) {
6192
6208
function lastSaved ( resourceName , id ) {
6193
6209
var DS = this ;
6194
6210
var resource = DS . store [ resourceName ] ;
6211
+
6212
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
6195
6213
if ( ! DS . definitions [ resourceName ] ) {
6196
6214
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
6197
6215
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6282,6 +6300,7 @@ function link(resourceName, id, relations) {
6282
6300
6283
6301
relations = relations || [ ] ;
6284
6302
6303
+ id = DS . utils . resolveId ( definition , id ) ;
6285
6304
if ( ! definition ) {
6286
6305
throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
6287
6306
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6495,6 +6514,8 @@ function linkInverse(resourceName, id, relations) {
6495
6514
6496
6515
relations = relations || [ ] ;
6497
6516
6517
+
6518
+ id = DS . utils . resolveId ( definition , id ) ;
6498
6519
if ( ! definition ) {
6499
6520
throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
6500
6521
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6562,6 +6583,8 @@ function errorPrefix(resourceName, id) {
6562
6583
*/
6563
6584
function previous ( resourceName , id ) {
6564
6585
var DS = this ;
6586
+
6587
+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
6565
6588
if ( ! DS . definitions [ resourceName ] ) {
6566
6589
throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
6567
6590
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6648,6 +6671,7 @@ function unlinkInverse(resourceName, id, relations) {
6648
6671
6649
6672
relations = relations || [ ] ;
6650
6673
6674
+ id = DS . utils . resolveId ( definition , id ) ;
6651
6675
if ( ! definition ) {
6652
6676
throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
6653
6677
} else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6918,6 +6942,22 @@ module.exports = [function () {
6918
6942
remove : require ( 'mout/array/remove' ) ,
6919
6943
slice : require ( 'mout/array/slice' ) ,
6920
6944
sort : require ( 'mout/array/sort' ) ,
6945
+ resolveItem : function ( resource , idOrInstance ) {
6946
+ if ( resource && ( this . isString ( idOrInstance ) || this . isNumber ( idOrInstance ) ) ) {
6947
+ return resource . index [ idOrInstance ] || idOrInstance ;
6948
+ } else {
6949
+ return idOrInstance ;
6950
+ }
6951
+ } ,
6952
+ resolveId : function ( definition , idOrInstance ) {
6953
+ if ( this . isString ( idOrInstance ) || this . isNumber ( idOrInstance ) ) {
6954
+ return idOrInstance ;
6955
+ } else if ( idOrInstance && definition ) {
6956
+ return idOrInstance [ definition . idAttribute ] || idOrInstance ;
6957
+ } else {
6958
+ return idOrInstance ;
6959
+ }
6960
+ } ,
6921
6961
updateTimestamp : function ( timestamp ) {
6922
6962
var newTimestamp = typeof Date . now === 'function' ? Date . now ( ) : new Date ( ) . getTime ( ) ;
6923
6963
if ( timestamp && newTimestamp <= timestamp ) {
0 commit comments