# Set\_table\_name not working in 2.3.5

**URL:** <https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671>\
**Category:** Rails\
**Created:** [February 1, 2010, 10:18am UTC](https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671 "2010-02-01T10:18:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@gigg](https://www.ruby-forum.com/u/gigg)\
**Post date:** [February 1, 2010, 10:18am UTC](https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671/1 "2010-02-01T10:18:29Z")

</div>

I am new to rails and developed a simple task in an app that runs  
every while using crontab. Under previous versions of rails it worked  
fine. But, I have upgraded the server, installed rails 2.3.5 as per  
rubygems latest and it now breaks the task.

When I run the task I get this error:

Mysql::Error: Table ‘cnms.odma\_units’ doesn’t exist: SELECT \* FROM  
`odma_units` ORDER BY device\_id

The Controller has always had and still has the following item set:

ActiveRecord::Base.set\_table\_name “odma\_unit”  
ActiveRecord::Base.set\_primary\_key “device\_id”

It also needs this as the type table is used by the present database,  
not quiet a legacy, but lets call it one for ease of understanding:  
ActiveRecord::Base.set\_inheritance\_column :category

The model has this in it which also worked:  
establish\_connection :cnms

Then obviously the config/database.yml file has this:

cnms:  
adapter: mysql  
encoding: utf8  
reconnect: false  
database: cnms  
pool: 5  
username: myuser  
password: mypass  
host: thehostaddress  
port: 3306  
socket: /var/run/mysqld/mysqld.sock

It now doesnt seem to allow single table usage. Does anyone know why  
as I cant seem to find an answer in google, etc, etc, etc.

Thanks

Gigg

---

<div class="post-metadata">

**Author:** ![gigg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@gigg](https://www.ruby-forum.com/u/gigg)\
**Post date:** [February 1, 2010, 10:24am UTC](https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671/2 "2010-02-01T10:24:20Z")

</div>

On Feb 1, 8:50 am, Gigg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The Controller has always had and still has the following item set:
> 
> ActiveRecord::Base.set\_table\_name “odma\_unit”  
> ActiveRecord::Base.set\_primary\_key “device\_id”

That’s weird - Why are you not calling set\_table\_name /  
set\_primary\_key on some subclass of ActiveRecord::Base ?

Fred

---

<div class="post-metadata">

**Author:** ![gigg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@gigg](https://www.ruby-forum.com/u/gigg)\
**Post date:** [February 2, 2010, 7:40am UTC](https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671/3 "2010-02-02T07:40:53Z")

</div>

Frederick C. wrote:

> On Feb 1, 8:50ï¿½am, Gigg [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > The Controller has always had and still has the following item set:
> > 
> > ActiveRecord::Base.set\_table\_name “odma\_unit”  
> > ActiveRecord::Base.set\_primary\_key “device\_id”
> 
> That’s weird - Why are you not calling set\_table\_name /  
> set\_primary\_key on some subclass of ActiveRecord::Base ?
> 
> Fred

Hi Fred,

I dont understand what you mean? Can you elaborate? I had it working  
before under the controller and model and it worked. Has something  
changed that I should know about?

Thanks

Gigg

---

<div class="post-metadata">

**Author:** ![gigg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@gigg](https://www.ruby-forum.com/u/gigg)\
**Post date:** [February 2, 2010, 9:34am UTC](https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671/4 "2010-02-02T09:34:04Z")

</div>

On Feb 2, 6:40 am, Grant G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Frederick C. wrote:

> 

The normal way of doing this is

class OdmaUnit \< ActiveRecord::Base  
set\_table\_name “odma\_unit”  
set\_primary\_key “device\_id”  
end

Fred

---

<div class="post-metadata">

**Author:** ![gigg](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/13edae/32.png) [@gigg](https://www.ruby-forum.com/u/gigg)\
**Post date:** [February 2, 2010, 9:51pm UTC](https://www.ruby-forum.com/t/set-table-name-not-working-in-2-3-5/182671/5 "2010-02-02T21:51:27Z")

</div>

I found the problem. All items concerned should be in the model and not  
the controller. You can read about it on my blog if you need help with  
multiple databases and the like.

> **[Multiple Databases for Rails](http://mygrantness.blogspot.com/2010/02/multi-databasess-for-rails.html)**
>
> I had to write a solution for a legacy database to join a current database. In essence I had 3 databases to work with, and needed the app to...

Thanks Fred for the help.
