@@ -10,6 +10,8 @@ import hasOne from 'ember-jsonapi-resources/utils/has-one';
1010import hasMany from 'ember-jsonapi-resources/utils/has-many' ;
1111import { isType } from 'ember-jsonapi-resources/utils/is' ;
1212
13+ const { computed, Logger } = Ember ;
14+
1315/**
1416 A Resource class to create JSON API resource objects
1517
@@ -230,7 +232,7 @@ const Resource = Ember.Object.extend({
230232 @method changedAttributes
231233 @return {Object } the changed attributes
232234 */
233- changedAttributes : Ember . computed ( 'attributes' , {
235+ changedAttributes : computed ( 'attributes' , {
234236 get : function ( ) {
235237 const attrs = { } ;
236238 for ( let key in this . _attributes ) {
@@ -248,7 +250,7 @@ const Resource = Ember.Object.extend({
248250 @method previousAttributes
249251 @return {Object } the previous attributes
250252 */
251- previousAttributes : Ember . computed ( 'attributes' , {
253+ previousAttributes : computed ( 'attributes' , {
252254 get : function ( ) {
253255 const attrs = { } ;
254256 for ( let key in this . _attributes ) {
@@ -347,7 +349,7 @@ const Resource = Ember.Object.extend({
347349 @property isCacheExpired
348350 @type Boolean
349351 */
350- isCacheExpired : Ember . computed ( 'meta.timeStamps.local' , 'cacheDuration' , function ( ) {
352+ isCacheExpired : computed ( 'meta.timeStamps.local' , 'cacheDuration' , function ( ) {
351353 const localTime = this . get ( 'meta.timeStamps.local' ) ;
352354 const expiresTime = localTime + this . get ( 'cacheDuration' ) ;
353355 return ( localTime ) ? Date . now ( ) >= expiresTime : false ;
@@ -366,7 +368,8 @@ Resource.reopenClass({
366368
367369 ```
368370 model() {
369- return this.container.lookupFactory('model:post').create({
371+ let owner = (typeof Ember.getOwner === 'function') ? Ember.getOwner(this) : this.container;
372+ return owner.lookup('model:post').create({
370373 attributes: {
371374 title: 'The JSON API 1.0 Spec Rocks!'
372375 }
@@ -399,14 +402,16 @@ Resource.reopenClass({
399402 let msg = ( type ) ? Ember . String . capitalize ( type ) : 'Resource' ;
400403 let factory = 'model:' + type ;
401404 if ( ! type ) {
402- Ember . Logger . warn ( msg + '#create called, instead you should first use ' + msg + '.extend({type:"entity"})' ) ;
405+ Logger . warn ( msg + '#create called, instead you should first use ' + msg + '.extend({type:"entity"})' ) ;
403406 } else {
404- if ( instance . container ) {
405- useComputedPropsMetaToSetupRelationships ( factory , instance ) ;
407+ let owner = ( typeof Ember . getOwner === 'function' ) ? Ember . getOwner ( instance ) : instance . container ;
408+ if ( owner ) {
409+ useComputedPropsMetaToSetupRelationships ( owner , factory , instance ) ;
406410 } else {
407- msg += '#create should only be called from a container lookup (relationships not setup) ' ;
408- msg += 'use this.container.lookupFactory("' + factory + '").create() instead.' ;
409- Ember . Logger . warn ( msg ) ;
411+ msg += '#create should only be called from a container lookup (relationships not setup), instead use: \n' ;
412+ msg += "`let owner = (typeof Ember.getOwner === 'function') ? Ember.getOwner(this) : this.container; \n" ;
413+ msg += 'owner.lookup("' + factory + '").create()`' ;
414+ Logger . warn ( msg ) ;
410415 }
411416 }
412417 return instance ;
@@ -420,8 +425,8 @@ export { attr, hasOne, hasMany };
420425let _rp = 'service type id attributes relationships links meta _attributes isNew cacheDuration isCacheExpired' ;
421426const ignoredMetaProps = _rp . split ( ' ' ) ;
422427
423- function useComputedPropsMetaToSetupRelationships ( factory , instance ) {
424- factory = instance . container . lookupFactory ( factory ) ;
428+ function useComputedPropsMetaToSetupRelationships ( owner , factory , instance ) {
429+ factory = owner . lookup ( factory ) ;
425430 factory . eachComputedProperty ( function ( prop ) {
426431 if ( ignoredMetaProps . indexOf ( prop ) > - 1 ) { return ; }
427432 try {
0 commit comments