I think the problem here was the ember-auth plugin I had a dependency on. It was somehow interferring my application. Removing this plugin solved the problem for me. :)
ember model not being found in store in route
-
29-07-2023 - |
Question
What i feel like I am doing is very basic yet I'm getting an undefined object everytime, I have an application called Example and have defined an ApplicationRoute:
Example.ApplicationRoute = Em.Route.extend({
model: function() {
var user = this.store.find('user',1);
console.log("username: " + user.username);
return { user: user };
}
});
And My Model:
var attr = DS.attr
Example.User = DS.Model.extend({
//logged in state can be loggedIn, loggedOff, pending, failed
loggedInState: attr('string'),
token: attr('string'),
username: attr('string'),
firstName: attr('string'),
lastName: attr('string'),
email: attr('string'),
isLoggedIn: Em.computed.match('loggedInState', /loggedIn/)
});
And lastly a FIXTURE:
Example.User.FIXTURES = [
{
id: 1,
username: 'jxnagl',
loggedInState: 'loggedOn',
firstName: 'Jared',
lastName: 'Nagle',
token: '1234',
email: 'jared.nagle@example.com'
}
]
It is my understanding that this FIXTURE will be present in the store by the time the model hook is called in the Application Route, But when i access my application, I get the following message in my console:
"username: undefined"
Is there something I'm missing? Ember's documentation shows similar examples and I don't see a difference.
Solution 2
OTHER TIPS
"find" returns promise.
var user = this.store.find('user', 1).then(function(user){
console.log('username: ' + user.get('username'));
});
I think your Route should be like
Example.ApplicationRoute = Em.Route.extend({
model: function() {
return this.store.find('user',1);
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow