Hi!
My model looks like this (example):
class Bank < ActiveRecord::Base
has_and_belongs_to_many :currencies
# other stuff
end
When I want to get some bank from database i do:
bank = Bank.first :joins => :some_table,
:conditions => {
#some conditions
}
Now, is there any way to explicitly retrieve currencies from database for provided conditions and sort them in some order and store them in bank.currencies ?
I'm doing something like this:
bank.currencies.reject! { |c| c.value < something }
bank.currencies.sort! { |x,y| x.value <=> y.value }
It works but this way I retrieve all records and filter them by myself. I would like to have DBMS do it for me.
This is just an example with banks and currencies. I have some big records and I think it is important just to retrieve those which interest me.