How can I limit the number of rows returned in a has many relationship? For example:
class User < ActiveRecord::Base
has_many :photos
end
I want to be able to do:
User.includes(:photos => {:limit => 8}).all
This obviously doesnt work, but something with this functionality. Do I need to write out the SQL myself?
Thanks in advance!
EDIT:
I dont want to limit the association, just the query results. So a User might have a thousand photos, I only want the top 3 returned.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…