If I have the following classes
class User
has_many :documents
end
class Document
belongs_to :user
end
I would like to be able to do the following
User.where("id > 200").documents
which should generate SQL like
select * from documents
join users on documents.user_id == users.id
where users.id > 200
but activerecord is not that clever. Is this an unreasonable thing to expect to be possible out of the box?
== A possible anti DRY solution ==
class User
has_many :documents
def self.documents
Documents.joins(:users).merge(self.scoped)
end
end
but this is not very DRY as it seems to replicate the relations I have already defined.