Querying calculated fields of ActiveRecord

I realize this thread is quite old, but I recently solved a similar
problem, and ran into similar difficulties.

In my situation, I wanted to return, along with other attributes, the
distance between an address and another fixed coordinate on Earth.
Performance is high on my list, so I wrote a pl/pgsql function to avoid
excessive marshalling (and for convenience), but when I started to port
my PHP application to RoR, I ran into the problem you describe.

The best solution I could come up with that balances performance, ease
of use and the OO features/limitations of AR was to, in summary:

1. Create a database view which selects all of the columns from the
table in which you're interested, including your calculated column. Be
sure to alias your calculated column (geo_distance in my case).
2. Generate an AR class which binds to the view (either naturally by
naming it appropriately, or by calling 'set_table_name "my_view"' in
code.
3. Code custom find_* methods as needed. This will give you free
access to your calculated columns.

Obviously, you can't update a database view, so don't even try calling
.save(!) on any MyView objects. I solved my need to update the table
involved in the DB view by generating a second AR class bound to the
table itself.

Actually you can if my memory serves me right... you just need to write triggers that fire for insert/update/delete that modify the underlying tables instead of the view... now how well that works with Rails I don't know, but my memory (years ago) is that once done it's done...

Might be an option for you... might not.