# Ignoring columns?

**URL:** <https://www.ruby-forum.com/t/ignoring-columns/141104>\
**Category:** Rails\
**Created:** [June 22, 2008, 3:20am UTC](https://www.ruby-forum.com/t/ignoring-columns/141104 "2008-06-22T03:20:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [June 22, 2008, 3:20am UTC](https://www.ruby-forum.com/t/ignoring-columns/141104/1 "2008-06-22T03:20:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [June 22, 2008, 3:55am UTC](https://www.ruby-forum.com/t/ignoring-columns/141104/2 "2008-06-22T03:55:14Z")

</div>

A\> Spank the legacy programmer who threw everything into one table  
instead of normalizing it all out

B\> add an SQL View that only selects what you need, then base the  
AR on this View…

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [June 22, 2008, 4:05am UTC](https://www.ruby-forum.com/t/ignoring-columns/141104/3 "2008-06-22T04:05:45Z")

</div>

A. Believe me I’d love to… He’s 5 states away. ☹

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.

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [June 22, 2008, 9:15am UTC](https://www.ruby-forum.com/t/ignoring-columns/141104/4 "2008-06-22T09:15:30Z")

</div>

> 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

* * *

TRIX - Ruby on Rails Development (available for hire)  
[http://en.trix.pl](http://en.trix.pl)

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [June 22, 2008, 2:39pm UTC](https://www.ruby-forum.com/t/ignoring-columns/141104/5 "2008-06-22T14:39:53Z")

</div>

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](http://datamapper.org/why.html)  
look at the bit on “lazy loading”

---

<div class="post-metadata">

**Author:** ![starmaerker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@starmaerker](https://www.ruby-forum.com/u/starmaerker)\
**Post date:** [June 22, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/ignoring-columns/141104/6 "2008-06-22T21:11:43Z")

</div>

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
