我有这样的模式:
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
如何通过参加<条码>:特殊-内容条码>作者协会,选择每一条<条码>。 我实际上想要做的是:
select * from discussions
inner join comments on comments.discussion_id=discussion.id
where comments.author = poopface
我就此说几句:
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 )
但是,它应当成为WHERE (“comments”.”author” = poopface
。
感谢!