# ActiveRecord find on legacy database having enum columns problem

**URL:** <https://www.ruby-forum.com/t/activerecord-find-on-legacy-database-having-enum-columns-problem/175093>\
**Category:** Rails\
**Created:** [September 7, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/activerecord-find-on-legacy-database-having-enum-columns-problem/175093 "2009-09-07T21:47:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [September 7, 2009, 9:47pm UTC](https://www.ruby-forum.com/t/activerecord-find-on-legacy-database-having-enum-columns-problem/175093/1 "2009-09-07T21:47:08Z")

</div>

hello,

Im interfacing a PHP app with my rails app and one of the tables im  
trying to do a find on has an enum column. So when i run the find, its  
adding an extra condition. This is my first time interfacing with a DB  
like this so im not quite sure how to remedy my problem

This is my named\_scope  
named\_scope :ads, lambda { |advertiser| { :conditions =\>  
[“advertiser\_id = ? && type = ?”, advertiser, “advertisement”]}

this is what i get in the terminal

SELECT \* FROM `broadcast` WHERE (advertiser\_id = ‘5’ && type =  
‘advertisement’) AND ( (`broadcast`.`type` = ‘Broadcast’ ) )

so its appending the (`broadcast`.`type` = ‘Broadcast’ ). There is a  
type column in the DB that is an enum column.

any help?

---

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [September 7, 2009, 11:36pm UTC](https://www.ruby-forum.com/t/activerecord-find-on-legacy-database-having-enum-columns-problem/175093/2 "2009-09-07T23:36:01Z")

</div>

2009/9/7 Bob O [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> [“advertiser\_id = ? && type = ?”, advertiser, “advertisement”]}
> 
> this is what i get in the terminal
> 
> SELECT \* FROM `broadcast` WHERE (advertiser\_id = ‘5’ && type =  
> ‘advertisement’) AND ( (`broadcast`.`type` = ‘Broadcast’ ) )
> 
> so its appending the (`broadcast`.`type` = ‘Broadcast’ ). There is a  
> type column in the DB that is an enum column.

The problem is that the column is named ‘type’. This is a reserved  
word in rails as it used in Single Table Inheritance. If you can  
change the name of the column then that should sort it. If you can’t  
change it then  
[http://www.benlog.org/2007/1/16/legacy-rails-beware-of-type-columns](http://www.benlog.org/2007/1/16/legacy-rails-beware-of-type-columns)  
provides a work around.

Colin

---

<div class="post-metadata">

**Author:** ![Bob\_O](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/5e9695/32.png) [@Bob\_O](https://www.ruby-forum.com/u/Bob_O)\
**Post date:** [September 8, 2009, 12:24am UTC](https://www.ruby-forum.com/t/activerecord-find-on-legacy-database-having-enum-columns-problem/175093/3 "2009-09-08T00:24:36Z")

</div>

Excellent. Thank you for the link. That worked great!
