class Question < ActiveRecord::Base
belongs_to :author
end
class Author < ActiveRecord::Base
has_many :questions
end
当我发现一些问题时,我通常需要同时获取他们的作者,所以我使用:
Question.find(:all, :include=>:authors)
但我不会到处写“:include”部分。我希望我能在某个地方只定义一次“包含”,当我发现问题时,会自动加载作者。有没有办法做到这一点?