# How to filter ActiveRecords.find using a facade column?

**URL:** <https://www.ruby-forum.com/t/how-to-filter-activerecords-find-using-a-facade-column/84662>\
**Category:** Rails\
**Created:** [February 6, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/how-to-filter-activerecords-find-using-a-facade-column/84662 "2007-02-06T20:18:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [February 6, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/how-to-filter-activerecords-find-using-a-facade-column/84662/1 "2007-02-06T20:18:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [February 6, 2007, 8:30pm UTC](https://www.ruby-forum.com/t/how-to-filter-activerecords-find-using-a-facade-column/84662/2 "2007-02-06T20:30:02Z")

</div>

On 2/6/07, Mike [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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 C.  
[http://depixelate.com](http://depixelate.com)

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [February 6, 2007, 8:33pm UTC](https://www.ruby-forum.com/t/how-to-filter-activerecords-find-using-a-facade-column/84662/3 "2007-02-06T20:33:02Z")

</div>

Zack,

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

```

Thank you
