Reputation: 6684
I have a model, Consultation
, and it has two fields :date
and :original_date
. Is it possible to pull all consultations where :date
is greater than one year after :original_date
without looping through all consultations
?
I tried something like this but it didn't work:
Consultation.where("date >= ?", self.original_date + 1.year)
Upvotes: 1
Views: 105
Reputation: 14900
If you're using Postgres you can do this
Consultation.where("date >= (original_date + INTERVAL '1 year')")
https://www.postgresql.org/docs/current/functions-datetime.html
Upvotes: 1