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!
After upgrading to v4 and replacing all of our
searchwithquery, this is something we noticed.If you use
queryinside of a search method,querygets set tonilinstead of carrying over from thebase_queryor any previous search methods. An example may be the best way to explain.Working
Not Working
I'm not sure what's going on that
queryis being set tonilbefore it hits the method if you locally definequeryin the method.It's pretty easy to work around by using
new_queryor 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!