{"action":"created","issue":{"url":"https://api.github.com/repos/glebm/order_query/issues/8","labels_url":"https://api.github.com/repos/glebm/order_query/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/glebm/order_query/issues/8/comments","events_url":"https://api.github.com/repos/glebm/order_query/issues/8/events","html_url":"https://github.com/glebm/order_query/issues/8","id":77115302,"number":8,"title":".previous always showing first record when limiting scope","user":{"login":"maskott","id":4070380,"avatar_url":"https://avatars.githubusercontent.com/u/4070380?v=3","gravatar_id":"","url":"https://api.github.com/users/maskott","html_url":"https://github.com/maskott","followers_url":"https://api.github.com/users/maskott/followers","following_url":"https://api.github.com/users/maskott/following{/other_user}","gists_url":"https://api.github.com/users/maskott/gists{/gist_id}","starred_url":"https://api.github.com/users/maskott/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maskott/subscriptions","organizations_url":"https://api.github.com/users/maskott/orgs","repos_url":"https://api.github.com/users/maskott/repos","events_url":"https://api.github.com/users/maskott/events{/privacy}","received_events_url":"https://api.github.com/users/maskott/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-16T20:03:43Z","updated_at":"2015-05-16T22:34:05Z","closed_at":null,"body":"First of all, I am a total noob, so sorry if I have this set up incorrectly or if this is not the proper channel to communicate this type of issue. I still have so much to learn!\r\n\r\nI have your order_query gem working beautifully for my Bottle class as such:\r\n```ruby\r\nclass Bottle < ActiveRecord::Base\r\n  ....\r\n  include OrderQuery\r\n  order_query :order_home,\r\n    [:name],\r\n    [:id]\r\nend\r\n```\r\nWhen I use it in my controller like `@b = Bottle.order_home_at(@bottle)`, everything works as expected. I can use `@b.next.id` and `@b.previous.id` to do what I'm trying to accomplish. \r\n\r\nHowever, when I try to limit the scope of the query to match my UI, with something like this `@b = Bottle.order(:name, :id).includes(:liquor_type).where(\"liquor_types.name\" => params[:type]).order_home_at(@bottle)` I run into what may be a bug.\r\n\r\nI seem to be able to use `@b.next.id` with expected behavior, but `@b.previous.id` always returns the `id` of the _first_ record in the intended set.\r\n\r\nAm I doing something wrong (probably), or have I discovered a bug? Thank you for your help and for making such a cool gem!"},"comment":{"url":"https://api.github.com/repos/glebm/order_query/issues/comments/102706703","html_url":"https://github.com/glebm/order_query/issues/8#issuecomment-102706703","issue_url":"https://api.github.com/repos/glebm/order_query/issues/8","id":102706703,"user":{"login":"glebm","id":216339,"avatar_url":"https://avatars.githubusercontent.com/u/216339?v=3","gravatar_id":"","url":"https://api.github.com/users/glebm","html_url":"https://github.com/glebm","followers_url":"https://api.github.com/users/glebm/followers","following_url":"https://api.github.com/users/glebm/following{/other_user}","gists_url":"https://api.github.com/users/glebm/gists{/gist_id}","starred_url":"https://api.github.com/users/glebm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/glebm/subscriptions","organizations_url":"https://api.github.com/users/glebm/orgs","repos_url":"https://api.github.com/users/glebm/repos","events_url":"https://api.github.com/users/glebm/events{/privacy}","received_events_url":"https://api.github.com/users/glebm/received_events","type":"User","site_admin":false},"created_at":"2015-05-16T22:34:05Z","updated_at":"2015-05-16T22:34:05Z","body":"Order query uses ActiveRecord's `#order` method (not `#reorder`) to add the `ORDER BY` clause. It probably should use `reorder`. Meanwhile, try removing the `.order()` from your scope, i.e.:\r\n\r\n```ruby\r\nBottle.includes(:liquor_type).where(liquor_types: {name: params[:type]}).\r\n    order_home_at(@bottle)\r\n```"}}