# ActiveRecord with Legacy Database

**URL:** <https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669>\
**Category:** Rails\
**Created:** [February 13, 2006, 4:38pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669 "2006-02-13T16:38:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zachary\_Zolton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@Zachary\_Zolton](https://www.ruby-forum.com/u/Zachary_Zolton)\
**Post date:** [February 13, 2006, 4:38pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669/1 "2006-02-13T16:38:01Z")

</div>

Hiya RoR gurus,

I work at a .NET shop, but I enjoy learning Ruby. So, I wanna  
prototype some of our product’s screens using Rails (and hopefullly  
AJAX). One thing I’m not sure about, since I’m a Rails noob, is  
whether ActiveRecord will get along with our database…

So I have two questions:

- Can I have ActiveRecord get along with our PascalCase naming  
conventions?

- We ALWAYS have two fields as our primary key: Id and  
EffectiveYear, which is an integer containing a year and a version, ie  
200600000, 200600001, … This is a strict requirement, so can I get  
ActiveRecord to do this (easily)?

Thanks in advance,

ZachZ

---

<div class="post-metadata">

**Author:** ![Zachary\_Zolton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@Zachary\_Zolton](https://www.ruby-forum.com/u/Zachary_Zolton)\
**Post date:** [February 13, 2006, 4:48pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669/2 "2006-02-13T16:48:11Z")

</div>

Hi, I’m not a guru, but I also work with legacy tables.

> - Can I have ActiveRecord get along with our PascalCase naming  
> conventions?  
> I think so. Mostly anything in rails can be overriden. If your tables’  
> names are not underscored, you can set\_table\_name in the models to your  
> PascalCase names. And you can always access your columns’ names through  
> the model using the PascalCase without a hitch.

> - We ALWAYS have two fields as our primary key: Id and  
> EffectiveYear, which is an integer containing a year and a version, ie  
> 200600000, 200600001, … This is a strict requirement, so can I get  
> ActiveRecord to do this (easily)?  
> My partial conclusion is that you cannot specify primary key with two  
> columns in the current rails. My workaround is to create a view that  
> combines the two keys into one key called id, and for any tables that  
> FKs this id, I created a view with a FK alias of the name  
> referencedtable\_id just so I don’t need to do overriding in the models.  
> Sinmce you’re just prototyping, this can be quick and effective.

good luck!

---

<div class="post-metadata">

**Author:** ![Zachary\_Zolton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@Zachary\_Zolton](https://www.ruby-forum.com/u/Zachary_Zolton)\
**Post date:** [February 13, 2006, 4:56pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669/3 "2006-02-13T16:56:47Z")

</div>

I can try making few views like you said for a prototype, but we have  
A LOT of tables, so that would not be optimal in the future! Hmm…  
Maybe there’s some more ideas out there…?

---

<div class="post-metadata">

**Author:** ![Zachary\_Zolton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@Zachary\_Zolton](https://www.ruby-forum.com/u/Zachary_Zolton)\
**Post date:** [February 13, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669/4 "2006-02-13T17:10:25Z")

</div>

> I can try making few views like you said for a prototype, but we have  
> A LOT of tables, so that would not be optimal in the future! Hmm…  
> Maybe there’s some more ideas out there…?

Once you’ve tried on a few views, you could extract some general trends  
out  
of your legacy tables and automate the process (write a tool which will  
generate the rails models with the default overriden for instance).

hope this helps

Thibaut

---

<div class="post-metadata">

**Author:** ![Zachary\_Zolton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@Zachary\_Zolton](https://www.ruby-forum.com/u/Zachary_Zolton)\
**Post date:** [February 13, 2006, 5:11pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669/5 "2006-02-13T17:11:13Z")

</div>

> Once you’ve tried on a few views, you could extract some general trends  
> out of your legacy tables and automate the process (write a  
> tool which will generate the rails models with the default overriden for  
> instance).

edit: the tool in question could be ruby+erb, or CodeSmith if you want  
to do  
that in c# 🙂

cheers

-T

---

<div class="post-metadata">

**Author:** ![Zachary\_Zolton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/85e7bf/32.png) [@Zachary\_Zolton](https://www.ruby-forum.com/u/Zachary_Zolton)\
**Post date:** [February 13, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/activerecord-with-legacy-database/53669/6 "2006-02-13T17:14:20Z")

</div>

Not a bad idea… They all have the same two fields for primary key:  
Id and EffectiveYear
