@@ -2373,6 +2373,7 @@ function destroy(resourceName, id, options) {
23732373
23742374 options = options || { } ;
23752375
2376+ id = DS . utils . resolveId ( definition , id ) ;
23762377 if ( ! definition ) {
23772378 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
23782379 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -3095,6 +3096,7 @@ function refresh(resourceName, id, options) {
30953096
30963097 options = options || { } ;
30973098
3099+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
30983100 if ( ! DS . definitions [ resourceName ] ) {
30993101 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
31003102 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -3180,6 +3182,7 @@ function save(resourceName, id, options) {
31803182
31813183 options = options || { } ;
31823184
3185+ id = DS . utils . resolveId ( definition , id ) ;
31833186 if ( ! definition ) {
31843187 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
31853188 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -3330,6 +3333,7 @@ function update(resourceName, id, attrs, options) {
33303333
33313334 options = options || { } ;
33323335
3336+ id = DS . utils . resolveId ( definition , id ) ;
33333337 if ( ! definition ) {
33343338 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
33353339 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -4411,6 +4415,7 @@ function bindOne(scope, expr, resourceName, id, cb) {
44114415 var DS = this ;
44124416 var IA = DS . errors . IA ;
44134417
4418+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
44144419 if ( ! DS . utils . isObject ( scope ) ) {
44154420 throw new IA ( errorPrefix ( resourceName ) + 'scope: Must be an object!' ) ;
44164421 } else if ( ! DS . utils . isString ( expr ) ) {
@@ -4487,6 +4492,8 @@ function changeHistory(resourceName, id) {
44874492 var DSUtils = DS . utils ;
44884493 var definition = DS . definitions [ resourceName ] ;
44894494 var resource = DS . store [ resourceName ] ;
4495+
4496+ id = DS . utils . resolveId ( definition , id ) ;
44904497 if ( resourceName && ! DS . definitions [ resourceName ] ) {
44914498 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
44924499 } else if ( id && ! DSUtils . isString ( id ) && ! DSUtils . isNumber ( id ) ) {
@@ -4551,6 +4558,8 @@ function errorPrefix(resourceName) {
45514558 */
45524559function changes ( resourceName , id ) {
45534560 var DS = this ;
4561+
4562+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
45544563 if ( ! DS . definitions [ resourceName ] ) {
45554564 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
45564565 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -4655,6 +4664,7 @@ function compute(resourceName, instance) {
46554664 var IA = DS . errors . IA ;
46564665 var definition = DS . definitions [ resourceName ] ;
46574666
4667+ instance = DS . utils . resolveItem ( DS . store [ resourceName ] , instance ) ;
46584668 if ( ! definition ) {
46594669 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
46604670 } else if ( ! DS . utils . isObject ( instance ) && ! DS . utils . isString ( instance ) && ! DS . utils . isNumber ( instance ) ) {
@@ -5211,6 +5221,8 @@ function _eject(definition, resource, id) {
52115221function eject ( resourceName , id ) {
52125222 var DS = this ;
52135223 var definition = DS . definitions [ resourceName ] ;
5224+
5225+ id = DS . utils . resolveId ( definition , id ) ;
52145226 if ( ! definition ) {
52155227 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
52165228 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -5540,6 +5552,8 @@ function diffIsEmpty(utils, diff) {
55405552 */
55415553function hasChanges ( resourceName , id ) {
55425554 var DS = this ;
5555+
5556+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
55435557 if ( ! DS . definitions [ resourceName ] ) {
55445558 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
55455559 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6127,6 +6141,8 @@ function errorPrefix(resourceName, id) {
61276141function lastModified ( resourceName , id ) {
61286142 var DS = this ;
61296143 var resource = DS . store [ resourceName ] ;
6144+
6145+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
61306146 if ( ! DS . definitions [ resourceName ] ) {
61316147 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
61326148 } else if ( id && ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6192,6 +6208,8 @@ function errorPrefix(resourceName, id) {
61926208function lastSaved ( resourceName , id ) {
61936209 var DS = this ;
61946210 var resource = DS . store [ resourceName ] ;
6211+
6212+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
61956213 if ( ! DS . definitions [ resourceName ] ) {
61966214 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
61976215 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6282,6 +6300,7 @@ function link(resourceName, id, relations) {
62826300
62836301 relations = relations || [ ] ;
62846302
6303+ id = DS . utils . resolveId ( definition , id ) ;
62856304 if ( ! definition ) {
62866305 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
62876306 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6495,6 +6514,8 @@ function linkInverse(resourceName, id, relations) {
64956514
64966515 relations = relations || [ ] ;
64976516
6517+
6518+ id = DS . utils . resolveId ( definition , id ) ;
64986519 if ( ! definition ) {
64996520 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
65006521 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6562,6 +6583,8 @@ function errorPrefix(resourceName, id) {
65626583 */
65636584function previous ( resourceName , id ) {
65646585 var DS = this ;
6586+
6587+ id = DS . utils . resolveId ( DS . definitions [ resourceName ] , id ) ;
65656588 if ( ! DS . definitions [ resourceName ] ) {
65666589 throw new DS . errors . NER ( errorPrefix ( resourceName , id ) + resourceName ) ;
65676590 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6648,6 +6671,7 @@ function unlinkInverse(resourceName, id, relations) {
66486671
66496672 relations = relations || [ ] ;
66506673
6674+ id = DS . utils . resolveId ( definition , id ) ;
66516675 if ( ! definition ) {
66526676 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
66536677 } else if ( ! DS . utils . isString ( id ) && ! DS . utils . isNumber ( id ) ) {
@@ -6918,6 +6942,22 @@ module.exports = [function () {
69186942 remove : require ( 'mout/array/remove' ) ,
69196943 slice : require ( 'mout/array/slice' ) ,
69206944 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+ } ,
69216961 updateTimestamp : function ( timestamp ) {
69226962 var newTimestamp = typeof Date . now === 'function' ? Date . now ( ) : new Date ( ) . getTime ( ) ;
69236963 if ( timestamp && newTimestamp <= timestamp ) {
0 commit comments