samedi 13 juin 2015

getting store attr in a route emberjs

I'm fetching a user using:

var user = this.store.find('user', user_id);

here is the user model:

export default DS.Model.extend({
  username: DS.attr('string'),
  email: DS.attr('string'),
  first_name: DS.attr('string'),
  last_name: DS.attr('string'),
  password: DS.attr('string'),
  is_admin: DS.attr('boolean')
});

im trying to run a before model where i check if the user is an admin and then do something if its true or false, example:

beforeModel: function(){
    var user  = this.store.find('user', 1);

    if(user.get('is_admin')){
        return 'do something since they are an admin';
    }
},

I also tried doing this instead:

beforeModel: function(){
    var user  = this.store.find('user', 1);

    return user.then(function(response){
        if(response.is_admin){
            return 'do something since they are an admin';
        }
    });
},

How can I get that is_admin attribute in a route?




Aucun commentaire:

Enregistrer un commentaire