Experimenting an issue trying to achieve a virtual attributes of a model in another controller. Is there a way to do it?
Here is the virtual attributes:
def montant
self.facture_details.sum(:montant_detail)
end
def paiements
self.facture_paiements.sum(:montant)
end
def facture_statut
if self.paiements < self.montant
then
"Ouverte"
else
"Payée"
end
end
And in another controller I'm trying to do:
@factures = Facture.find(:all, :conditions => {:facture_statut => 'Ouverte'})
When I do this I got an error:
SQLite3::SQLException: no such column: factures.facture_statut: SELECT "factures".* FROM "factures" WHERE "factures"."facture_statut" = 'Ouverte'
Is there someone to help me with this?
Thanks
Update; here is the full model:
class Facture < ActiveRecord::Base
has_many :facture_details, :dependent => :destroy
has_many :facture_paiements
accepts_nested_attributes_for :facture_details, :allow_destroy => true
accepts_nested_attributes_for :facture_paiements
attr_accessor :facture_statut
attr_accessor :montant
attr_accessor :paiements
def montant
self.facture_details.sum(:montant_detail)
end
def paiements
self.facture_paiements.sum(:montant)
end
def facture_statut
if self.paiements < self.montant
then
"Ouverte"
else
"Payée"
end
end
end