Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behaviour when combining scopes with OR #140

Open
dlupu opened this issue Feb 1, 2011 · 2 comments
Open

Strange behaviour when combining scopes with OR #140

dlupu opened this issue Feb 1, 2011 · 2 comments

Comments

@dlupu
Copy link

dlupu commented Feb 1, 2011

Hello,

I'm currently implementing a search form in our users database. I would like to search by id , by login or by email.

Naturally, I think that the best aproach is to combine scopes and simplify the form. So I added a text_field for :id_or_login_or_email_like.

Everything works fine when I type a number in the text-field.

However, when I type a word and press search, the value i typed is losed and replaced with a 0 (zero) and the search result returns all users that have 0 in the ID, name or login.

Any ideas on how to fix this? I'm using Rails 2.3.2 and SearchLogic 2.4.27.
Thanks!

@dlupu
Copy link
Author

dlupu commented Feb 1, 2011

Got an answer on StackOverFlow. I'm copy/paste it here, hoping someone will clear the mistery:

"I think this is because your scope is making a comparison against an integer when comparing to id, which causes your string to be converted to 0. Try using .dup to ensure that the passed attribute to the scope is not changed."

Source: http://stackoverflow.com/questions/4857721/searchlogic-strange-behaviour-when-combining-scopes-with-or

@dlupu
Copy link
Author

dlupu commented Feb 1, 2011

Never mind, I found a workaround: when combining scopes with OR, put the scope related to integer values at the end.

So instead of :id_or_login_or_email_like use login_or_email_or_id_like. This seems like a bug to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant