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

Inverted "not_" AR scopes #497

Open
h0jeZvgoxFepBQ2C opened this issue Aug 17, 2017 · 5 comments
Open

Inverted "not_" AR scopes #497

h0jeZvgoxFepBQ2C opened this issue Aug 17, 2017 · 5 comments

Comments

@h0jeZvgoxFepBQ2C
Copy link

h0jeZvgoxFepBQ2C commented Aug 17, 2017

Hi,

It would be nice to have also inverted automatic ActiveRecord scopes, like f.e. for a Sms-Model:

state :delivered

=> SmsMessage.delivered

It would be nice if we would add the "not_" scopes as well:

=> SmsMessage.not_delivered

# like SmsMessage.where("aasm_state <> (?)", STATE_DELIVERED)

If you like, I can open a PR? Just tell me if you would accept such a change or if you have any thoughts about this?

@h0jeZvgoxFepBQ2C h0jeZvgoxFepBQ2C changed the title Inverted "not_" scopes Inverted "not_" AR scopes Aug 17, 2017
@derikson
Copy link

derikson commented Mar 8, 2018

Another option is to allow a boolean argument, inverted that defaults to false. Then you would use SmsMessage.delivered(false). I prefer this when you have filters where the user may turn it on or off, because then you only have to change the argument instead of using #send to change the method name.

@timlawrenz
Copy link

@h0jeZvgoxFepBQ2C are you still considering submitting a PR?

@grozwalker
Copy link

Hello everyone!

Do you have any news on this task? I think it would be convenient!

I'm ready to do PR

@danielricecodes
Copy link

Hello everyone!

Do you have any news on this task? I think it would be convenient!

I'm ready to do PR

@grozwalker - checkout #795 and upvote please 👍

@fauno
Copy link

fauno commented Feb 29, 2024

I came here to propose something similar, but I was thinking on automatic scopes for events, something like Model.may_event to get all models that could transition to an event. Is it something for another issue? Not sure I can provide a PR in the short term...

Edit: change verb :P

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

6 participants