I have models like this:
class Discussion < ActiveRecord::Base
has_many :comments
has_one :special_comment, :class_name => "Comment"
end
class Comment < ActiveRecord::Base
belongs_to :discussion
# contains author
end
How can I select every Discussion
through its adjoined :special_comment
'author' association. Effectively I want to do something like:
select * from discussions
inner join comments on comments.discussion_id=discussion.id
where comments.author = 'poopface'
I get something close with this:
Discussion.find(:all, :conditions => {:author => 'poopface'}, :joins => :special_comment) ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column: discussions.author: SELECT "discussions".* FROM "discussions" INNER JOIN "comments" ON comments.discussion_id = discussions.id WHERE ("discussions"."author" = 'poopface')
But it should be WHERE ("comments"."author" = 'poopface')
Thanks!