Zeck
Zeck

Reputation: 6579

Eager loading with limit?

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])

Upvotes: 0

Views: 152

Answers (2)

Sachin R
Sachin R

Reputation: 11876

default_scope includes(:comments :user).limit(5)

Add it to default scope

Event.find(params[:id])

Upvotes: 0

Valery Kvon
Valery Kvon

Reputation: 4496

scope :with_comments, include(comments: :user).limit(5)

Upvotes: 2

Related Questions