class Transaction < ActiveRecord::Base
belongs_to :account, :polymorphic => true
end
class Bankaccount < ActiveRecord::Base
has_many :transactions, :as => :account
end
class Creditcard < ActiveRecord::Base
has_many :transactions, :as => :account
end
Trying to do a summation of transactions where the account is active.
Transaction.sum(:all, :conditions => "account.status = 'active'", :include => :account)
So after some reading I came across this: The reason is that the parent model‘s type is a column value so its corresponding table name cannot be put in the FROM/JOIN clauses of that query. The table name is bankaccounts and creditcards so does that mean they should be singular? Also the account_type is a string either Bankaccount or Creditcard to reflect the model but should it be the tablename instead?