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?
import Ember from 'ember';
export default Ember.Component.extend({
onUpdate: function() {
Ember.RSVP.hash({
user: this.get('user'),
currentUser: this.get('session.user')
}).then(function(hash) {
this.set('isCurrentUser', !!(hash.user && hash.currentUser && hash.user.get('id') === hash.currentUser.get('id'))));
}.bind(this));
},
onUser: function() {
this.onUpdate();
}.observes('user').on('init'),
onCurrentUser: function() {
this.onUpdate();
}.observes('session.user').on('init')
});
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.
Aucun commentaire:
Enregistrer un commentaire