limit the number of objects returned in a has_many
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. ronnieonrails Just add a limit option to the has_many association: class User < ActiveRecord::Base has_many :photos, :limit => 8