bradphelan/Active-Illusion — Issue #1: Joins for ordering?
Author: jaylevitt
Created: 2011-11-24 22:09:05+00:00
State: open

Have you figured out how to trick ActiveRecord into joining against this fake table? For instance, I have:

class Score < ActiveRecord::Illusion
column :question_id, :integer
column :score, :float

belongs_to :question

view do
select{[s.question_id.as(question_id), s.score.as(score)]}.from("scores() as s")
end

end

and then I'd like to do something like

Question.includes(:score).order("scores.score desc")

but `.includes` doesn't actually do the join, and adding `.joins(:score)` doesn't work since it expects a real table by that name, and doesn't look to the model for details.