-
Notifications
You must be signed in to change notification settings - Fork 59
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
Ransackable scopes #57
base: master
Are you sure you want to change the base?
Conversation
Scopes are special in that they don't have a predicate. This removes the check for the predicate, and thus makes scopes as filtering options work with JSONAPI.rb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking this over! I like your solution, but I have a question regarding requiring the scope's name to be an allowed_field
.
Also, thank you for maintaining these gems, they really help us!
allow = predicates.any? || ( | ||
predicates.none? && | ||
scopes.include?(requested_field) && | ||
allowed_fields.include?(requested_field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, given that we handle scopes separately already, I don't really see why we should add the scopes to the allowed_fields
array as well. Most scopes will have names that don't directly match the name of a field, so I think this would be a little confusing.
However, I might be missing something as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most scopes will have names that don't directly match the name of a field, so I think this would be a little confusing.
Yup, I was thinking about it too and the only reason I'd leave it explicit, is because there might be scopes that can conflict with the field name. My concern is that we might accidentally enable a scope as filterable without the user being aware of it.
@fluxsaas would be nice to get your opinion on this too. 🙇
Any updates on this idea? Was just trying to do this today. |
Also just ran into this |
Dealing with this now, nice solution! |
I'll have to make it backwards compatible, but definitely could have it released by next week. Ty ty for bringing it all up! |
Checking in on this status as well. Any updates? |
Any updates? This would be very helpful to get merged. |
What is the current behavior?
ActiveRecord scopes can't be used in filters. This supersedes the #54
What is the new behavior?
You can use scopes for filtering as well, to enable scopes, use the option
flags:
Assuming your model
User
has the following scope defined:This allows you to run queries like:
Checklist
Please make sure the following requirements are complete:
features)