I’m trying to get all records from my model with associated records as well and then generate json with .to_json. I’m using Rails 2.3.
Here is piece of part of the model:
class Currency
has_many :exchange_from, :class_name => "CurrencyExchange", :foreign_key => "currency_from_id", :dependent => :destroy
has_many :exchange_to, :class_name => "CurrencyExchange", :foreign_key => "currency_to_id", :dependent => :destroy
And that is code that I thought will work:
Currency.all(:include => [:exchange_from, :exchange_to]).to_json
But result is exacly the same as I would do simply Currency.all.to_json. If it’s impossible to achive my goal using ActiveRecord please guide me what kind of SQL should I use.
Do this:
Documentation here.