Skip to content

Instantly share code, notes, and snippets.

@jknipp
Created April 22, 2011 20:43
Show Gist options
  • Save jknipp/937571 to your computer and use it in GitHub Desktop.
Save jknipp/937571 to your computer and use it in GitHub Desktop.
class Account < ActiveRecord::Base
set_primary_key "AccountId"
belongs_to :bank, :foreign_key => 'CompanyId'
scope :mcm_bank_and_account_number, lambda { |mcm_bank_id, acct|
joins(:bank).
where("bank.MCMBankNumber = ? AND account.AccountNumber = ?", mcm_bank_id, acct).merge(Bank.mcm_bank)
}
...
end
class Bank < ActiveRecord::Base
set_primary_key "BankId"
has_many :accounts, :foreign_key => 'CompanyId'
alias_attribute :CompanyId, :BankId
# Set default ordering
default_scope :order => 'MCMBankNumber ASC'
scope :mcm_bank, lambda { where("bank.BankTypeId = ?", 1) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment