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

Custom scope within grouping does not apply filter #1339

Open
thisismydesign opened this issue Jun 9, 2022 · 4 comments
Open

Custom scope within grouping does not apply filter #1339

thisismydesign opened this issue Jun 9, 2022 · 4 comments

Comments

@thisismydesign
Copy link

thisismydesign commented Jun 9, 2022

This query simply ignores custom_scope.

Model.ransack({ groupings: [{custom_scope: 'bla'}]}).result.to_sql

Scope is defined as:

scope :custom_scope, ->(name) { ... }

def self.ransackable_scopes(_auth_object = nil)
  [:custom_scope]
end

Possibly related to #653 but here it's silently doing a wrong behavior instead of raising an error.

This sadly breaks activeadmin_addons's Ajax search integration when using custom scopes.

Is there a way to work around this?

@Roguelazer
Copy link

This is also breaking a use-case over here. Quick/reproducible demo:

Here's another minimal scope definition for reproducing:

scope :example_scope, ->(value) do
  where(id: value)
end

And here's some example interaction:

> puts SavedGrant.example_scope(2).to_sql
SELECT "saved_grants".* FROM "saved_grants" WHERE "saved_grants"."id" = 2

> puts SavedGrant.ransack({example_scope: 2}).result.to_sql
SELECT "saved_grants".* FROM "saved_grants" WHERE "saved_grants"."id" = 2

> puts SavedGrant.ransack(g: [{example_scope: 2}]).result.to_sql
SELECT "saved_grants".* FROM "saved_grants"

# other filters work fine in groupings
> puts SavedGrant.ransack({g: [{id_eq: 3}, {example_scope: 2}], m: "and"}).result.to_sql
SELECT "saved_grants".* FROM "saved_grants" WHERE "saved_grants"."id" = 3

Looking at the code, it looks sort of like scopes are "bolted on" after everything else (see add_scope in search.rb, and I don't see a very straightforward way to add support for them to the core Condition class. Maybe I'm wrong?

@sudiptam123
Copy link

sudiptam123 commented Mar 19, 2024

I have a similar query added for select-search filter as here. Pls clarify on this. The end result is that, results aren't filtered in the way it is expected to be.

@sudiptam123
Copy link

I have a similar query added for select-search filter as here. Pls clarify on this. The end result is that, results aren't filtered in the way it is expected to be.

I found the solution for this issue. Seems upgrading activeadmin-addons from 1.7.x to 1.10.x is working correctly. Hence this issue is resolved

@devsheva
Copy link

any updates to this? i think i have the same issue #1490

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

4 participants