Append a criteria to each Db query

I have a database table which stores events. The table has a ‘event_date’ column and each event row has a ‘event_date’ column. On querying the table I want only the future events. In SQL query we can do this by adding, ‘event_date >= NOW()’ the where condition.

My question is in Yii, can we write a filter or an action which appends the above criteria, so that I don’t have to mention this criteria in each and every query that is made to the database table?

There are many ways this can be accomplished. Here are two:

  1. Model Level

Add a default scope with this condition.

  1. Reusable

Create a new ActiveRecord behavior that applies this condition to models using it.

Thanks. I will have to read the documentation properly now. :)