I'm developing a web application about gift lists in Rails 3. I'd would like to get all the purchases for a certain list. These are the models and their relationships:
class Gift < ActiveRecord::Base
belongs_to :list
has_many :purchases
class List < ActiveRecord::Base
has_many :gifts
class Purchase < ActiveRecord::Base
belongs_to :gift
So, basically, I've tried the following code (I don't think it's the best way to do this at all), and eventhough the results are correct, I've realized that I get a Gift object instead of a Purchase:
@purchases = List.find(params[:id]).gifts.joins(:purchases).select("purchases.*")
Any ideas?