简体   繁体   中英

Rails, Postgres, ActiveRecord query postgres based on columns value

I working with Rails and Postgresql and I'm trying to query my postgres db based on the value of a column.

To put it into perspective, I have an Events table in postgres and in that table I have some events that are recurring and some that aren't based on the column value of repeats .

If the events recur, then they will have a value of daily , weekly , monthly , etc. inside of the repeats column. Obviously, if it doesn't recur then the value will be set to null .

I would like to receive only those events that recur in the repeats column. So if it's null, then the query will skip over it.

I've looked through the ActiveRecord Query Interface but due to my inexperience, I was unable to find a helper that would do the trick for me.

Please let me know if more info is needed.

Any advice will be greatly appreciated. Thanks!

Event.where.not(repeats: nil)

或者,您可以指定一个sql流

Event.where("repeats is not null")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM