How to filter ActiveRecords.find using a facade column?

Hello

    I have a ActiveRecord class that has a facade column, this column calculates some values using several columns of the table, I want to filter using :conditions at .find, e.g. (Items.Find :all, :conditions "usage_rate > 5000" (usage_rate is a def in active record class, not a column in table) obviously at run time it returns an error about SQL unknown column. By now I created a column and populate it every time the query is made, but it is not an optimal solution. So, how can I filter records found by .find and use this records in paginate or whatever I need to exposo that data?

Thank you

Miguel Guzman

If you have to paginate off the column then you really should permanently add the column to the DB (with an index on it). A simple migration should take care of this. Then update this usage column via a callback on the appropriate AR model or using a DB trigger.

The reason this is the only viable choice is that the only other option is to find(:all) and then sort in ruby which makes no sense from a performance perspective.

Zack,

    I supposed that, it's what I'm going to do.

Thank you