@@ -3515,6 +3515,14 @@ function loadRelations(resourceName, instance, relations, options) {
35153515 relations = [ relations ] ;
35163516 }
35173517
3518+ if ( DSUtils . isArray ( instance ) ) {
3519+ var instances = [ ] ;
3520+ angular . forEach ( instance , function ( object ) {
3521+ instances . push ( DS . get ( resourceName , object ) ) ;
3522+ } ) ;
3523+ instance = instances ;
3524+ }
3525+
35183526 if ( ! definition ) {
35193527 throw new DS . errors . NER ( errorPrefix ( resourceName ) + resourceName ) ;
35203528 } else if ( ! DSUtils . isObject ( instance ) ) {
@@ -3537,40 +3545,46 @@ function loadRelations(resourceName, instance, relations, options) {
35373545 var tasks = [ ] ;
35383546 var fields = [ ] ;
35393547
3540- DSUtils . forEach ( definition . relationList , function ( def ) {
3541- var relationName = def . relation ;
3542- if ( DSUtils . contains ( relations , relationName ) ) {
3543- var task ;
3544- var params = { } ;
3545- if ( options . allowSimpleWhere ) {
3546- params [ def . foreignKey ] = instance [ definition . idAttribute ] ;
3547- } else {
3548- params . where = { } ;
3549- params . where [ def . foreignKey ] = {
3550- '==' : instance [ definition . idAttribute ]
3551- } ;
3552- }
3548+ if ( DSUtils . isArray ( instance ) ) {
3549+ angular . forEach ( instance , function ( object ) {
3550+ tasks . push ( DS . loadRelations ( resourceName , object , relations , options ) ) ;
3551+ } ) ;
3552+ } else {
3553+ DSUtils . forEach ( definition . relationList , function ( def ) {
3554+ var relationName = def . relation ;
3555+ if ( DSUtils . contains ( relations , relationName ) ) {
3556+ var task ;
3557+ var params = { } ;
3558+ if ( options . allowSimpleWhere ) {
3559+ params [ def . foreignKey ] = instance [ definition . idAttribute ] ;
3560+ } else {
3561+ params . where = { } ;
3562+ params . where [ def . foreignKey ] = {
3563+ '==' : instance [ definition . idAttribute ]
3564+ } ;
3565+ }
35533566
3554- if ( def . type === 'hasMany' && params [ def . foreignKey ] ) {
3555- task = DS . findAll ( relationName , params , options ) ;
3556- } else if ( def . type === 'hasOne' ) {
3557- if ( def . localKey && instance [ def . localKey ] ) {
3567+ if ( def . type === 'hasMany' && params [ def . foreignKey ] ) {
3568+ task = DS . findAll ( relationName , params , options ) ;
3569+ } else if ( def . type === 'hasOne' ) {
3570+ if ( def . localKey && instance [ def . localKey ] ) {
3571+ task = DS . find ( relationName , instance [ def . localKey ] , options ) ;
3572+ } else if ( def . foreignKey && params [ def . foreignKey ] ) {
3573+ task = DS . findAll ( relationName , params , options ) . then ( function ( hasOnes ) {
3574+ return hasOnes . length ? hasOnes [ 0 ] : null ;
3575+ } ) ;
3576+ }
3577+ } else if ( instance [ def . localKey ] ) {
35583578 task = DS . find ( relationName , instance [ def . localKey ] , options ) ;
3559- } else if ( def . foreignKey && params [ def . foreignKey ] ) {
3560- task = DS . findAll ( relationName , params , options ) . then ( function ( hasOnes ) {
3561- return hasOnes . length ? hasOnes [ 0 ] : null ;
3562- } ) ;
35633579 }
3564- } else if ( instance [ def . localKey ] ) {
3565- task = DS . find ( relationName , instance [ def . localKey ] , options ) ;
3566- }
35673580
3568- if ( task ) {
3569- tasks . push ( task ) ;
3570- fields . push ( def . localField ) ;
3581+ if ( task ) {
3582+ tasks . push ( task ) ;
3583+ fields . push ( def . localField ) ;
3584+ }
35713585 }
3572- }
3573- } ) ;
3586+ } ) ;
3587+ }
35743588
35753589 deferred . resolve ( ) ;
35763590
0 commit comments