如何向此范围添加limit
?
scope :with_comments, include: {comments: :user}
我正在使用它:
Event.with_comments.find(params[:id])
答案 0 :(得分:2)
scope :with_comments, include(comments: :user).limit(5)
答案 1 :(得分:0)
default_scope includes(:comments :user).limit(5)
将其添加到默认范围
Event.find(params[:id])