Using the following component in ember-cli (component name if-current-user
) the promise for a belongsTo on model.user resolves to null until I save an unrelated model into the store. How do I get it to resolve to the User object associated with the record?
export default Ember.Component.extend({
userId: Ember.computed.alias('user.id'),
currentUserId: Ember.computed.alias('session.user.id'),
isCurrentUser: function() {
return !!(this.get('userId') && this.get('currentUserId') && this.get('userId') === this.get('currentUserId'));
}.property('userId', 'currentUserId')
});
Model:
import DS from 'ember-data';
export default DS.Model.extend({
user: DS.belongsTo('user', { async: true }),
timestamp: DS.attr('number')
});
Template:
{{#if-current-user user=model.user}}
{{#link-to "route.edit" model}}Edit{{/link-to}}
{{/if-current-user}}
Note that I'm injecting the current session into all components, routes and controllers.