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

Fix select queries using custom scopes #408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thisismydesign
Copy link

Fixes #407

AFAICT the following queries are equivalent:

User.ransack({ groupings: [{m: 'or', firstname_contains: 'a', lastname_contains: 'a'}, combinator: 'and']}).result.to_sql
# "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"deleted_at\" IS NULL AND (\"users\".\"firstname\" ILIKE '%a%' OR \"users\".\"lastname\" ILIKE '%a%')"

User.ransack({m: 'or', firstname_contains: 'a', lastname_contains: 'a'}).result.to_sql
# "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"deleted_at\" IS NULL AND (\"users\".\"firstname\" ILIKE '%a%' OR \"users\".\"lastname\" ILIKE '%a%')"

Simplifying the query sent to activeadmin allows for custom scopes to be used in ajax select fields. It also simplifies the query :)

I didn't modify nested_select, I suspect that this implementation with grouping was made for that use case and then re-used for the more simple ones.

@thisismydesign
Copy link
Author

CI failure:

lint - Unauthorized

@thisismydesign
Copy link
Author

@ldlsegovia any chance you can take a look at this pr?

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

Successfully merging this pull request may close these issues.

Custom scopes don't work with Ajax Select
1 participant