SundayMonday
SundayMonday

Reputation: 19737

Limit and offset in Active Record joins

I'd like to apply a limit and offset to the following Active Record query:

results = ForumThread.joins(:posts).where(:posts => {:some_integer => 123})

Note ForumThread :has_many posts association in the model.

I tried including an @options hash in the where clause. I tried appending .limit(5) to the end of the query. However neither of these work. Reading Active Record Query Interface guide didn't help either. How can I apply limit and offset to my query?

I'm open to modifying the query if an alternative finder method is more appropriate.

Upvotes: 1

Views: 1794

Answers (1)

SundayMonday
SundayMonday

Reputation: 19737

The query contains COUNT(*) since I was calling results.count later. Apparently SELECT COUNT(*) ignores limit clauses hence appending LIMIT(5) to the query had no effect.

Upvotes: 1

Related Questions