How complex a query can ActiveRecord handle before it''s better using Raw SQL or a View???

Greg Hauptmann
Fri, 19 Dec 2008 01:25:28 -0000

Hi,

How complex a query can ActiveRecord handle before it''s better using
Raw SQL
or a View???

I need to calculate for example taxable income via a query going across 5
tables.  Some like this: Find all transaction records (transactions table),
for which they are allocated (via allocation table) to person X (person
table), for transaction dates within date1 & date2, for which the
category (categories table) associated with transaction, has a tax_id (from
tax_codes table) of XYZ.  I will need to reuse this type of query as I build
a report of various tax categories.

Question - What would Rails best practice way for the above?

[I''m thinking best to create a flat view of this and use this to then
query
against]

Thanks