{"action":"created","issue":{"url":"https://api.github.com/repos/amatsuda/kaminari/issues/839","repository_url":"https://api.github.com/repos/amatsuda/kaminari","labels_url":"https://api.github.com/repos/amatsuda/kaminari/issues/839/labels{/name}","comments_url":"https://api.github.com/repos/amatsuda/kaminari/issues/839/comments","events_url":"https://api.github.com/repos/amatsuda/kaminari/issues/839/events","html_url":"https://github.com/amatsuda/kaminari/issues/839","id":195515711,"number":839,"title":"Negative padding returns 0 objects if number of objects is less than negative padding value","user":{"login":"yo-gen","id":3635878,"avatar_url":"https://avatars.githubusercontent.com/u/3635878?v=3","gravatar_id":"","url":"https://api.github.com/users/yo-gen","html_url":"https://github.com/yo-gen","followers_url":"https://api.github.com/users/yo-gen/followers","following_url":"https://api.github.com/users/yo-gen/following{/other_user}","gists_url":"https://api.github.com/users/yo-gen/gists{/gist_id}","starred_url":"https://api.github.com/users/yo-gen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yo-gen/subscriptions","organizations_url":"https://api.github.com/users/yo-gen/orgs","repos_url":"https://api.github.com/users/yo-gen/repos","events_url":"https://api.github.com/users/yo-gen/events{/privacy}","received_events_url":"https://api.github.com/users/yo-gen/received_events","type":"User","site_admin":false},"labels":[{"id":77321,"url":"https://api.github.com/repos/amatsuda/kaminari/labels/Feedback%20Needed","name":"Feedback Needed","color":"03eb31","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-12-14T12:14:36Z","updated_at":"2016-12-20T10:41:28Z","closed_at":null,"body":"For eg. if I have 3 objects in array.\r\n\r\n```ruby\r\nmy_array = [1,2,3]\r\n```\r\n\r\nThen, `Kaminari.paginate_array(my_array).page(1).per(10).padding(-5)`\r\nreturns count as 0, and 0 objects in the result.\r\nIt should return back count as 3 and results as `[1,2,3]`\r\n\r\nI am using\r\nkaminari-0.17.0\r\nrails 4.2.7.1\r\nruby-2.3.1"},"comment":{"url":"https://api.github.com/repos/amatsuda/kaminari/issues/comments/268211318","html_url":"https://github.com/amatsuda/kaminari/issues/839#issuecomment-268211318","issue_url":"https://api.github.com/repos/amatsuda/kaminari/issues/839","id":268211318,"user":{"login":"amatsuda","id":11493,"avatar_url":"https://avatars.githubusercontent.com/u/11493?v=3","gravatar_id":"","url":"https://api.github.com/users/amatsuda","html_url":"https://github.com/amatsuda","followers_url":"https://api.github.com/users/amatsuda/followers","following_url":"https://api.github.com/users/amatsuda/following{/other_user}","gists_url":"https://api.github.com/users/amatsuda/gists{/gist_id}","starred_url":"https://api.github.com/users/amatsuda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatsuda/subscriptions","organizations_url":"https://api.github.com/users/amatsuda/orgs","repos_url":"https://api.github.com/users/amatsuda/repos","events_url":"https://api.github.com/users/amatsuda/events{/privacy}","received_events_url":"https://api.github.com/users/amatsuda/received_events","type":"User","site_admin":false},"created_at":"2016-12-20T10:41:28Z","updated_at":"2016-12-20T10:41:28Z","body":"I'm not strongly against the proposed behavior, but there exists a problem regarding negative padding.\r\n\r\nI investigated this issue a little bit, and found that negative padding with the  Array extension is completely broken. It actually returns such a funny result:\r\n\r\n```ruby\r\nKaminari.paginate_array([*1..10]).page(1).per(5).padding(-2)\r\n#=> [9, 10]\r\n```\r\n\r\nOTOH passing a negative number to `padding()` on an AR relation performs very differently. Actually it differs even between the adapters:\r\n\r\n* SQLite3\r\n```\r\nUser.page(1).per(5).padding(-2)\r\n User Load (0.2ms)  SELECT  \"users\".* FROM \"users\" LIMIT ? OFFSET ?  [[\"LIMIT\", 5], [\"OFFSET\", -2]]\r\n#=> [1, 2, 3, 4, 5]\r\n```\r\n\r\n* PostgreSQL\r\n```\r\nUser.page(1).per(5).padding(-2)\r\n  User Load (4.7ms)  SELECT  \"users\".* FROM \"users\" LIMIT $1 OFFSET $2  [[\"LIMIT\", 5], [\"OFFSET\", -2]]\r\nActiveRecord::StatementInvalid: PG::InvalidRowCountInResultOffsetClause: ERROR:  OFFSET must not be negative\r\n```\r\n\r\n* MySQL\r\n```\r\nUser.page(1).per(5).padding(-2)\r\n  User Load (2.9ms)  SELECT  `users`.* FROM `users` LIMIT 5 OFFSET -2\r\nActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2' at line 1: SELECT  `users`.* FROM `users` LIMIT 5 OFFSET -2\r\n```\r\n\r\nBased on this fact, I'm leaning towards rejecting negative padding, unless @yo-gen or anyone else submits a patch that nicely fixes the inconsistency between these adapters and Array."}}
{"actor":{"display_login":"amatsuda"}}