2013-01-16 82 views
0

如何將limit添加到此範圍?急於加載限制?

scope :with_comments, include: {comments: :user} 

我使用的是這樣的:

Event.with_comments.find(params[:id]) 
+0

這可能嗎? – Zeck

+1

檢查這個問題,你會得到你的答案http://stackoverflow.com/questions/9808674/rails-eager-load-and-limit – SSP

回答

2
scope :with_comments, include(comments: :user).limit(5) 
0
default_scope includes(:comments :user).limit(5) 

添加到默認範圍

Event.find(params[:id])