# Set\_table\_name on RoR 1.2.4

**URL:** <https://www.ruby-forum.com/t/set-table-name-on-ror-1-2-4/116927>\
**Category:** Rails\
**Created:** [October 11, 2007, 9:32am UTC](https://www.ruby-forum.com/t/set-table-name-on-ror-1-2-4/116927 "2007-10-11T09:32:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dima](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@dima](https://www.ruby-forum.com/u/dima)\
**Post date:** [October 11, 2007, 9:32am UTC](https://www.ruby-forum.com/t/set-table-name-on-ror-1-2-4/116927/1 "2007-10-11T09:32:47Z")

</div>

Unfortunately I had to work on some proprietary MSSQL database  
building some internal web application. Naturally, I use RoR 1.2.4.  
Even I add set\_table\_name and set\_primary\_key in Model (RegionalIndex)  
of mine it have made SQL requests using regional\_indexes as a table  
name.  
After spending some time I come with the solution witch puzzled me a  
bit.

The model is looks as follows:  
class Regionalindex \< ActiveRecord::Base  
set\_table\_name “RegionalIndex”  
set\_primary\_key “IndexID”  
end

and it not works as expected.

When I change it to  
class Regionalindex \< ActiveRecord::Base  
ActiveRecord::Base.set\_table\_name “RegionalIndex”  
ActiveRecord::Base.set\_primary\_key “IndexID”  
End

everything is performing OK.

Do you think it’s a little puzzling?

---

<div class="post-metadata">

**Author:** ![dima](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@dima](https://www.ruby-forum.com/u/dima)\
**Post date:** [October 11, 2007, 1:50pm UTC](https://www.ruby-forum.com/t/set-table-name-on-ror-1-2-4/116927/2 "2007-10-11T13:50:37Z")

</div>

On 10/11/07, dima [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class Regionalindex \< ActiveRecord::Base  
> End
> 
> everything is performing OK.
> 
> Do you think it’s a little puzzling?

Puzzling, and scary.

It would look like this would set the table name and primary key for  
ALL models. Actually it appears to set it for subsequent subclasses,  
including the one currently being defined if, as you have it, it’s in  
the context of a class definition. Here’s an experiment using rails  
from svn:

$ script/console  
Loading development environment (Rails 1.2.4)

```
  *******************************************************************
  * config.breakpoint_server has been deprecated and has no effect. 

```

- 

```
*******************************************************************

```

> > class A \< ActiveRecord::Base  
> > set\_table\_name “hey”  
> > end  
> > =\> nil  
> > A.table\_name  
> > =\> “hey”  
> > class B \< ActiveRecord::Base  
> > ActiveRecord::Base.set\_table\_name “bumble”  
> > end  
> > =\> nil  
> > B.table\_name  
> > =\> “bumble”  
> > ActiveRecord::Base.table\_name  
> > =\> “bumble”  
> > A.table\_name  
> > =\> “hey”  
> > class C \< ActiveRecord::Base  
> > ActiveRecord::Base.set\_table\_name “clamp”  
> > end  
> > =\> nil  
> > C.table\_name  
> > =\> “clamp”  
> > class D \< ActiveRecord::Base  
> > end  
> > =\> nil  
> > D.table\_name  
> > =\> “clamp”

So:

1. I don’t think that calling ActiveRecord::Base is a good idea, and

2. You need further investigation of why  
class Regionalindex \< ActiveRecord::Base  
set\_table\_name “RegionalIndex”  
set\_primary\_key “IndexID”  
end

Isn’t working.

## Perhaps it’s an issue with the mssql adapter?

Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)
