別のコントローラーでモデルの仮想属性を達成しようとする問題を実験しています。それを行う方法はありますか?
仮想属性は次のとおりです。
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
そして、私がやろうとしている別のコントローラーで:
@factures = Facture.find(:all, :conditions => {:facture_statut => 'Ouverte'})
これを行うと、エラーが発生しました:
SQLite3::SQLException: no such column: factures.facture_statut: SELECT "factures".* FROM "factures" WHERE "factures"."facture_statut" = 'Ouverte'
これを手伝ってくれる人はいますか?
ありがとう
アップデート; 完全なモデルは次のとおりです。
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