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

not_by_year: negate inclusion in range #90

Open
coorasse opened this issue Apr 22, 2021 · 0 comments
Open

not_by_year: negate inclusion in range #90

coorasse opened this issue Apr 22, 2021 · 0 comments

Comments

@coorasse
Copy link

coorasse commented Apr 22, 2021

I could not find an example in the documentation on how to achieve that.
I want to fetch all records not created in a specific year.

I don't like this approach:

[3] pry(main)> Reservation.where.not(id: Reservation.by_year(2020)).to_sql
=> "SELECT \"reservations\".* FROM \"reservations\" WHERE \"reservations\".\"id\" NOT IN (SELECT \"reservations\".\"id\" FROM \"reservations\" WHERE (reservations.created_at >= '2019-12-31 23:00:00' AND reservations.created_at <= '2020-12-31 22:59:59.999999'))"

because I get a nested query which is not necessary.

I tried:

Reservation.where.not((Reservation.by_year(2020).where_values_hash))

but it does not work since where_values_hash returns {}.

Help? 😄

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

1 participant