I have a Ruby on Rails model that has a column called expiration_date. Once the expiration date is reached, I want another column on the model to be modified (e.g. expired = true). What are some good ways of doing this?
Ideally I’d like a model function to be called at the exact moment the expiry date is reached.
For the scenario you describe, the best solution is to have an
expiredmethod instead of a column, that would return true iff theexpiration_dateis greater or equal than the current date.For other scenarios, I would go with a DB scheduled event triggering a stored procedure. That procedure would check the
expiration_datecolumn for all the rows in the model table, and update theexpired(or other(s)) column(s) accordingly.