Forum: Ruby on Rails ActiveRecord with Legacy Database

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
946696209f50381fc280e4c0a85cceb8?d=identicon&s=25 Zachary Zolton (Guest)
on 2006-02-13 16:38
(Received via mailing list)
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
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 xiheng xu (Guest)
on 2006-02-13 16:48
(Received via mailing list)
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!
946696209f50381fc280e4c0a85cceb8?d=identicon&s=25 Zachary Zolton (Guest)
on 2006-02-13 16:56
(Received via mailing list)
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...?
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (Guest)
on 2006-02-13 17:10
(Received via mailing list)
> 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
91eb330fb36d1e03c856574dfb77d2bc?d=identicon&s=25 Thibaut Barrère (Guest)
on 2006-02-13 17:11
(Received via mailing list)
> 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
946696209f50381fc280e4c0a85cceb8?d=identicon&s=25 Zachary Zolton (Guest)
on 2006-02-13 17:14
(Received via mailing list)
Not a bad idea...  They all have the same two fields for primary key:
Id and EffectiveYear
This topic is locked and can not be replied to.