3

So I was following this tutorial on authentication in EmberJS and when I added the initializer shown on that page it breaks my app.

This is the code that breaks the application

Ember.Application.initializer({ name: 'currentUser', initialize: function(container) { var store = container.lookup('store:main'); var user = App.User.find('current'); container.lookup('controller:currentUser').set('content', user); container.typeInjection('controller', 'currentUser', 'controller:currentUser'); } }); 

This is the error that happens

Uncaught TypeError: Object function () { if (!wasApplied) { Class.proto(); // prepare prototype... } o_defineProperty(this, GUID_KEY, undefinedDescriptor); o_defineProperty(this, '_super', undefinedDescriptor); var m = meta(this), proto = m.proto; m.proto = this; if (initMixins) { // capture locally so we can clear the closed over variable var mixins = initMixins; initMixins = null; this.reopen.apply(this, mixins); } if (initProperties) { // capture locally so we can clear the closed over variable var props = initProperties; initProperties = null; var concatenatedProperties = this.concatenatedProperties; for (var i = 0, l = props.length; i < l; i++) { var properties = props[i]; Ember.assert("Ember.Object.create no longer supports mixing in other definitions, use createWithMixins instead.", !(properties instanceof Ember.Mixin)); for (var keyName in properties) { if (!properties.hasOwnProperty(keyName)) { continue; } var value = properties[keyName], IS_BINDING = Ember.IS_BINDING; if (IS_BINDING.test(keyName)) { var bindings = m.bindings; if (!bindings) { bindings = m.bindings = {}; } else if (!m.hasOwnProperty('bindings')) { bindings = m.bindings = o_create(m.bindings); } bindings[keyName] = value; } var desc = m.descs[keyName]; Ember.assert("Ember.Object.create no longer supports defining computed properties.", !(value instanceof Ember.ComputedProperty)); Ember.assert("Ember.Object.create no longer supports defining methods that call _super.", !(typeof value === 'function' && value.toString().indexOf('._super') !== -1)); Ember.assert("`actions` must be provided at extend time, not at create time, when Ember.ActionHandler is used (i.e. views, controllers & routes).", !((keyName === 'actions') && Ember.ActionHandler.detect(this))); if (concatenatedProperties && indexOf(concatenatedProperties, keyName) >= 0) { var baseValue = this[keyName]; if (baseValue) { if ('function' === typeof baseValue.concat) { value = baseValue.concat(value); } else { value = Ember.makeArray(baseValue).concat(value); } } else { value = Ember.makeArray(value); } } if (desc) { desc.set(this, keyName, value); } else { if (typeof this.setUnknownProperty === 'function' && !(keyName in this)) { this.setUnknownProperty(keyName, value); } else if (MANDATORY_SETTER) { Ember.defineProperty(this, keyName, null, value); // setup mandatory setter } else { this[keyName] = value; } } } } } finishPartial(this, m); this.init.apply(this, arguments); m.proto = proto; finishChains(this); sendEvent(this, "init"); } has no method 'find' 
2
  • what page? and what version of ember.js are you using? Commented Sep 2, 2013 at 22:28
  • I only have the Index page and it's where it's happening. I'm running EmberJS 1.0.0 (latest) Commented Sep 2, 2013 at 22:33

1 Answer 1

5

In ember-data 1.0.0-beta the DS.Model subclasses like your App.User, doesn't have a find method. Instead you have to use:

  • store.find('user'); to find all data
  • store.find('user', id); to find by id
  • store.find('user', { key: name }); to find by query

The result is the following:

Ember.Application.initializer({ name: 'currentUser', initialize: function(container) { var store = container.lookup('store:main'); var user = store.find('user','current'); container.lookup('controller:currentUser').set('content', user); container.typeInjection('controller', 'currentUser', 'controller:currentUser'); } }); 

I hope it helps

Sign up to request clarification or add additional context in comments.

1 Comment

Hey Márcio, could you please point at some documentation related to that? Official docs here (emberjs.com/api/data/classes/DS.Store.html) are claiming that find is still there. And I don't get who should emit this initializer me or extension (i.e. Ember Data)?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.