@@ -4545,8 +4545,8 @@ var observe = require('../../../lib/observe-js/observe-js'),
4545
4545
errorPrefix = 'DS.inject(resourceName, attrs[, options]): ' ;
4546
4546
4547
4547
function _inject ( definition , resource , attrs ) {
4548
- var _this = this ,
4549
- $log = _this . $log ;
4548
+ var _this = this ;
4549
+ var $log = _this . $log ;
4550
4550
4551
4551
function _react ( added , removed , changed , getOldValueFn ) {
4552
4552
try {
@@ -4624,6 +4624,21 @@ function _inject(definition, resource, attrs) {
4624
4624
return injected ;
4625
4625
}
4626
4626
4627
+ function _injectRelations ( definition , injected ) {
4628
+ var _this = this ;
4629
+ _this . utils . forOwn ( definition . relations , function ( relation , type ) {
4630
+ _this . utils . forOwn ( relation , function ( def , relationName ) {
4631
+ if ( _this . definitions [ relationName ] && injected [ def . localField ] ) {
4632
+ try {
4633
+ injected [ def . localField ] = _this . inject ( relationName , injected [ def . localField ] ) ;
4634
+ } catch ( err ) {
4635
+ _this . $log . error ( errorPrefix + 'Failed to inject ' + type + ' relation: "' + relationName + '"!' , err ) ;
4636
+ }
4637
+ }
4638
+ } ) ;
4639
+ } ) ;
4640
+ }
4641
+
4627
4642
/**
4628
4643
* @doc method
4629
4644
* @id DS.sync_methods:inject
@@ -4680,19 +4695,23 @@ function inject(resourceName, attrs, options) {
4680
4695
throw new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ;
4681
4696
}
4682
4697
4683
- var definition = this . definitions [ resourceName ] ,
4684
- resource = this . store [ resourceName ] ,
4685
- _this = this ;
4698
+ var definition = this . definitions [ resourceName ] ;
4699
+ var resource = this . store [ resourceName ] ;
4700
+ var _this = this ;
4686
4701
4687
4702
try {
4688
4703
var injected ;
4689
4704
if ( ! this . $rootScope . $$phase ) {
4690
4705
this . $rootScope . $apply ( function ( ) {
4691
- injected = _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4706
+ injected = _inject . call ( _this , definition , resource , attrs ) ;
4692
4707
} ) ;
4693
4708
} else {
4694
- injected = _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4709
+ injected = _inject . call ( _this , definition , resource , attrs ) ;
4710
+ }
4711
+ if ( definition . relations ) {
4712
+ _injectRelations . call ( _this , definition , injected ) ;
4695
4713
}
4714
+
4696
4715
return injected ;
4697
4716
} catch ( err ) {
4698
4717
if ( ! ( err instanceof this . errors . RuntimeError ) ) {
0 commit comments