@@ -4545,8 +4545,8 @@ var observe = require('../../../lib/observe-js/observe-js'),
45454545 errorPrefix = 'DS.inject(resourceName, attrs[, options]): ' ;
45464546
45474547function _inject ( definition , resource , attrs ) {
4548- var _this = this ,
4549- $log = _this . $log ;
4548+ var _this = this ;
4549+ var $log = _this . $log ;
45504550
45514551 function _react ( added , removed , changed , getOldValueFn ) {
45524552 try {
@@ -4624,6 +4624,21 @@ function _inject(definition, resource, attrs) {
46244624 return injected ;
46254625}
46264626
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+
46274642/**
46284643 * @doc method
46294644 * @id DS.sync_methods:inject
@@ -4680,19 +4695,23 @@ function inject(resourceName, attrs, options) {
46804695 throw new this . errors . IllegalArgumentError ( errorPrefix + 'options: Must be an object!' , { options : { actual : typeof options , expected : 'object' } } ) ;
46814696 }
46824697
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 ;
46864701
46874702 try {
46884703 var injected ;
46894704 if ( ! this . $rootScope . $$phase ) {
46904705 this . $rootScope . $apply ( function ( ) {
4691- injected = _inject . apply ( _this , [ definition , resource , attrs ] ) ;
4706+ injected = _inject . call ( _this , definition , resource , attrs ) ;
46924707 } ) ;
46934708 } 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 ) ;
46954713 }
4714+
46964715 return injected ;
46974716 } catch ( err ) {
46984717 if ( ! ( err instanceof this . errors . RuntimeError ) ) {
0 commit comments