Marc
I believe you’re finding it difficult because your associations aren’t quite setup right.
If you want to use from_account_id and to_account_it in operations, this suggests two assocaitions
You might model it something like this.
class Account < ActiveRecord::Base
has_many :operations_from, :class_name => “Operations”, :foreign_key => “from_account_id”, :order => “actual_date”
has_many :operations_to, :class_name => “Operations”, :foreign_key => “to_account_id”, :order => “actual_date”
def has_operations?
operations_from.count > 0 || operations_to.count > 0
end
end
When you’re inside the account model you shouldn;t use Operation.find class methods much if at all. You should use the assocation methods setup by the has_many and belongs to.
You should use this version of your migrations for this.
create_table “operations”, :force => true do |t|
t.column "actual_date", :datetime
t.column "amount", :decimal
t.column "from_account_id", :integer
t.column "to_account_id", :integer
end
You should setup the belongs_to call similarly to the has_many
HTH
Daniel