{"action":"created","issue":{"url":"https://api.github.com/repos/jhund/filterrific/issues/28","labels_url":"https://api.github.com/repos/jhund/filterrific/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/jhund/filterrific/issues/28/comments","events_url":"https://api.github.com/repos/jhund/filterrific/issues/28/events","html_url":"https://github.com/jhund/filterrific/issues/28","id":53035518,"number":28,"title":"Chainning the existing scopes with Filterrific doesn't work when the filter is empty.","user":{"login":"vmeyet","id":2462303,"avatar_url":"https://avatars.githubusercontent.com/u/2462303?v=3","gravatar_id":"","url":"https://api.github.com/users/vmeyet","html_url":"https://github.com/vmeyet","followers_url":"https://api.github.com/users/vmeyet/followers","following_url":"https://api.github.com/users/vmeyet/following{/other_user}","gists_url":"https://api.github.com/users/vmeyet/gists{/gist_id}","starred_url":"https://api.github.com/users/vmeyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmeyet/subscriptions","organizations_url":"https://api.github.com/users/vmeyet/orgs","repos_url":"https://api.github.com/users/vmeyet/repos","events_url":"https://api.github.com/users/vmeyet/events{/privacy}","received_events_url":"https://api.github.com/users/vmeyet/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2014-12-29T11:36:09Z","updated_at":"2015-01-13T18:44:33Z","closed_at":"2015-01-13T18:44:33Z","body":"Chainning the existing scopes with Filterrific doesn't work when the filter is empty.\r\n\r\nHere is a simple example:\r\n\r\n```ruby\r\n# Assuming a feedback model having a rating (integer) column\r\nclass Feedback < ActiveRecord::Base\r\n  filterrific(filter_names: [:with_rating])\r\n  scope :no_low_rating, -> { where('rating > ?', 2) }\r\n  scope :with_rating, ->(keys) { where(rating: [*keys.to_s.split(',')]) }\r\nend\r\n\r\n# When there is a filter\r\nfilter = Filterrific.new(Feedback, with_rating: 2)\r\n# This will work\r\nFeedback.no_low_rating.filterrific_find(filter)\r\n# When there is no filter\r\nfilter = Filterrific.new(Feedback, {})\r\n# This won't work, it'll give me the ActiveRecord class Feedback\r\nFeedback.no_low_rating.filterrific_find(filter)\r\n# This will work but is damn ugly\r\nFeedback.filterrific_find(filter).all.scoping { Feedback.no_low_rating }\r\n```\r\n\r\n\r\nA fix seems to be the following (ruby 2.0.0 rails 4.1)\r\n\r\n```ruby\r\nmodule Filterrific\r\n  module ActiveRecordExtension\r\n    def filterrific_find(filterrific_param_set)\r\n      unless filterrific_param_set.is_a?(Filterrific::ParamSet)\r\n        raise(ArgumentError, \"Invalid Filterrific::ParamSet: #{ filterrific_param_set.inspect }\")\r\n      end\r\n\r\n      # set initial ar_proxy to including class\r\n      ar_proxy = self.all  # CHANGED `self` TO `self.all`\r\n\r\n      # apply filterrific params\r\n      self.filterrific_filter_names.each do |filter_name|\r\n        filter_param = filterrific_param_set.send(filter_name)\r\n        next if filter_param.blank? # skip blank filter_params\r\n        ar_proxy = ar_proxy.send(filter_name, filter_param)\r\n      end\r\n\r\n      ar_proxy\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nIt's seems to work for the other cases:\r\n  - when the filter isn't empty,\r\n  - or when you apply the second scope afterward"},"comment":{"url":"https://api.github.com/repos/jhund/filterrific/issues/comments/69795976","html_url":"https://github.com/jhund/filterrific/issues/28#issuecomment-69795976","issue_url":"https://api.github.com/repos/jhund/filterrific/issues/28","id":69795976,"user":{"login":"vmeyet","id":2462303,"avatar_url":"https://avatars.githubusercontent.com/u/2462303?v=3","gravatar_id":"","url":"https://api.github.com/users/vmeyet","html_url":"https://github.com/vmeyet","followers_url":"https://api.github.com/users/vmeyet/followers","following_url":"https://api.github.com/users/vmeyet/following{/other_user}","gists_url":"https://api.github.com/users/vmeyet/gists{/gist_id}","starred_url":"https://api.github.com/users/vmeyet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vmeyet/subscriptions","organizations_url":"https://api.github.com/users/vmeyet/orgs","repos_url":"https://api.github.com/users/vmeyet/repos","events_url":"https://api.github.com/users/vmeyet/events{/privacy}","received_events_url":"https://api.github.com/users/vmeyet/received_events","type":"User","site_admin":false},"created_at":"2015-01-13T18:44:33Z","updated_at":"2015-01-13T18:44:33Z","body":"Saw the fix! thanks"}}