activeadmin_addons icon indicating copy to clipboard operation
activeadmin_addons copied to clipboard

Fix select queries using custom scopes

Open thisismydesign opened this issue 3 years ago • 2 comments

Fixes https://github.com/platanus/activeadmin_addons/issues/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 avatar Jun 10 '22 09:06 thisismydesign

CI failure:

lint - Unauthorized

thisismydesign avatar Jun 10 '22 09:06 thisismydesign

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

thisismydesign avatar Jun 30 '22 22:06 thisismydesign