Ignoring columns?

Hi all,

Is there any way to specify that AR ignore certain columns?

I have a project where I have to connect to a legacy DB where I have a
very wide read only table (actually a view, but the result is the
same). The web app only needs about 1/2 of the columns, the other
stuff I don't need.

Other than specifying a select clause on every find (or a named scope
that applies the select I need), is there a way to tell ActiveRecord
to completely ignore certain columns, or as an alternative declared a
named scope to be applied to all finds of a Model, or declare as
default :select clause?

Any ideas would be greatly appreciated.

Thanks,

Andrew

Spank the legacy programmer who threw everything into one table

    instead of normalizing it all out

add an SQL View that only selects what you need, then base the

    AR on this View...

A. Believe me I'd love to.... He's 5 states away. :frowning:

B. You're assuming I have control of the DB.... NOT!! I have to deal
with what they give me. And yes, it's a MS SQL Server DB, it's hosted
at the other companies office, on the other end of an encrypted
VPN.... Sigh....

Got to love those MS devotees... At least I convinced them to give me
read access to the views, rather than doing absolutely everything
through stored procedures, which is what they originally wanted.

Is there any way to specify that AR ignore certain columns?

did you try :select option?

You can do this for example:

VeryWideTable.find(:all, :select => 'first_field, second_field')

it will produce SELECT first_field, second_field FROM very_wide_tables

instead of default SELECT * FROM very_wide_tables

It really make sense, if you need to perform queries fast, and don't
want to process big amount of incoming data

I hope that it will solve your problems

Tomek wrote:

Is there any way to specify that AR ignore certain columns?

You can do this for example:

VeryWideTable.find(:all, :select => 'first_field, second_field')

or you could move to Merb + DataMapper.
http://datamapper.org/why.html
look at the bit on "lazy loading"

Yeah,

That's what I'm doing. I'm trying to DRY up my code with out have to
tack on a select on every single find I use.

Andrew