0

How do I add a limit to this scope?

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

I'm using it like this:

Event.with_comments.find(params[:id])
tereško
  • 58,060
  • 25
  • 98
  • 150
Zeck
  • 6,433
  • 21
  • 71
  • 111
  • 1
    check this question you will get your answer http://stackoverflow.com/questions/9808674/rails-eager-load-and-limit – SSP Jan 16 '13 at 07:15

2 Answers2

2
scope :with_comments, include(comments: :user).limit(5)
Valery Kvon
  • 4,438
  • 1
  • 20
  • 15
0
default_scope includes(:comments :user).limit(5)

Add it to default scope

Event.find(params[:id])
Sachin R
  • 11,606
  • 10
  • 35
  • 40