So I am trying to filter my transactions by the selectedUser. I am not using sessions for the user system, instead I use a menu that updates selectedAt and I take the last selected user this way. Now I want to show the transactions only from the selected user. I've tried multple variants but they don't seem to work for me.
My controller looks like this
users: computed(function() {
return this.get('store').peekAll('user');
}),
selectedUser: computed('users.length', function() {
return this.get('users').sortBy('selectedAt').reverse().objectAt(0);
}),
transactions: computed(function() {
return this.get('store').findAll('transaction');
}),
My transaction model:
export default Model.extend({
category: DS.attr(),
name: DS.attr(),
description: DS.attr(),
amount: DS.attr(),
date: DS.attr(),
typeOfT: DS.attr(),
user: DS.belongsTo('user')
});
and my User model:
export default Model.extend({
fullName: DS.attr(),
picture: DS.attr(),
darkMode: DS.attr(),
selectedAt: DS.attr('date'),
transactions: DS.hasMany('transaction')
});
I can succesfully call each transaction for currentUser in the template by calling them like
Aucun commentaire:
Enregistrer un commentaire