limit the number of objects returned in a has_many

前端 未结 3 1907
迷失自我
迷失自我 2020-12-16 18:07

How can I limit the number of rows returned in a has many relationship? For example:

class User < ActiveRecord::Base
  has_many :photos
end
3条回答
  •  天涯浪人
    2020-12-16 18:56

    You can put a :limit on the actual has_many declaration.

    class User < ActiveRecord::Base
      has_many :photos, :limit => 8
    end
    

提交回复
热议问题