Skip to content

Instantly share code, notes, and snippets.

@athap
Created September 23, 2015 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athap/c87f9db3a7cae6923eba to your computer and use it in GitHub Desktop.
Save athap/c87f9db3a7cae6923eba to your computer and use it in GitHub Desktop.
u = User.find 1
// page 1
c1 = u.comments.where(disabled: 0).limit(50).page(1).per(20)
id1 = c1.map(&:id)
//page2
c2 = u.comments.where(disabled: 0).limit(50).page(2).per(20)
id2 = c2.map(&:id)
//page3
c3 = u.comments.where(disabled: 0).limit(50).page(2).per(20)
id3 = c3.map(&:id)
@andy128k
Copy link

This is what i mean. limit does to restrict page numbers

> u = User.find 1026651
=> #<User:220727060 @id=1026651>

> u.comments.count
=> 30

> c2 = u.comments.limit(10).page(12).per(2)
  Comment Load (39.2ms)  SELECT `comments`.* FROM `comments` WHERE `comments`.`user_id` = 1026651 LIMIT 2 OFFSET 22
=> [#<Comment:214995000 @id=546714>, #<Comment:215367840 @id=546805>]

@athap
Copy link
Author

athap commented Sep 23, 2015

I see the issue now. May be we should paginate 50 items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment