I'm trying to figure out how to pull all the records in my set where their fields publish
is true and expires
is less than today. I have the following but I don't think the less than part is working, can someone please point me on the right track?
Announcement.where(publish: true, :expires < Date.today)
Thanks in advance for your help
ActiveRecord::Base indicates that the ActiveRecord class or module has a static inner class called Base that you're extending.
Active Record is the M in MVC - the model - which is the layer of the system responsible for representing business data and logic. Active Record facilitates the creation and use of business objects whose data requires persistent storage to a database.
The Relation Class. Having queries return an ActiveRecord::Relation object allows us to chain queries together and this Relation class is at the heart of the new query syntax. Let's take a look at this class by searching through the ActiveRecord source code for a file called relation.
The Active Record Pattern is used to access the data stored in a relational database. It allows us to create, read, update, and delete data from a database. It is particularly used for persistently stored data. The Active Record Pattern is a part of the MVC design pattern.
Try this:
Announcement.where("publish = ? AND expires < ?", true, Date.today)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With