Skip to content

Redefining query in a search method sets it to nil. #37

Description

@joshuapinter

After upgrading to v4 and replacing all of our search with query, this is something we noticed.

If you use query inside of a search method, query gets set to nil instead of carrying over from the base_query or any previous search methods. An example may be the best way to explain.

Working

def search_last_name
  # query.class => Person::ActiveRecord_Relation
  query.where(last_name: last_name)
end
def search_last_name
  # query.class => Person::ActiveRecord_Relation
  new_query = query.where(last_name: last_name)
  new_query
end

Not Working

def search_last_name
  # query.class => NilClass
  query = query.where(last_name: last_name)
  query
end

I'm not sure what's going on that query is being set to nil before it hits the method if you locally define query in the method.

It's pretty easy to work around by using new_query or something similar but I'm curious if you were aware of this and if it's something that we can help fix.

I know you're more or less hands off with this gem (thanks for all your efforts by the way) but if you can help with this I may be able to help with some PRs to keep it maintained.

Many thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions