platanus / activeadmin_addons

Extends ActiveAdmin to enable a set of great optional UX improving add-ons
MIT License
763 stars 288 forks source link

Fix select queries using custom scopes #408

Open thisismydesign opened 2 years ago

thisismydesign commented 2 years ago

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 commented 2 years ago

CI failure:

lint - Unauthorized

thisismydesign commented 2 years ago

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