# Large, existing database for RoR

**URL:** <https://www.ruby-forum.com/t/large-existing-database-for-ror/82390>\
**Category:** Ruby\
**Created:** [March 16, 2006, 12:00am UTC](https://www.ruby-forum.com/t/large-existing-database-for-ror/82390 "2006-03-16T00:00:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 16, 2006, 12:00am UTC](https://www.ruby-forum.com/t/large-existing-database-for-ror/82390/1 "2006-03-16T00:00:56Z")

</div>

Hi,  
My organisation has a relatively large legacy database that has a java  
application (using hibernate) to perform analytics on the data.

We need to develop a CRUD application for it and I have been looking at  
Ruby on Rails and scffolding to do it. It does not need to be fancy  
interface at all, just have an ability for CRUD.

What I am concerning about is the Id field in RoR and having it change  
the datamodel. As other application are using it, is it possible to  
have RoR integrate directly with an exisitng data schema without  
changing it ? All the tutorials sort of do DB development when writing  
the web application.

Thanks in advance, it means a lot of time would be saved!

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 16, 2006, 12:16am UTC](https://www.ruby-forum.com/t/large-existing-database-for-ror/82390/2 "2006-03-16T00:16:11Z")

</div>

Yes, you can specify what the id is.

I suggest taking a look at [http://api.rubyonrails.org/](http://api.rubyonrails.org/)

Find on ActiveRecord::Base then within that, search for set\_primary\_key.

Basically this is what you want to set the primary key to invId for  
rails’ purposes:

class Invoice \< ActiveRecord::Base  
set\_primary\_key ‘invId’  
end

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 16, 2006, 12:19am UTC](https://www.ruby-forum.com/t/large-existing-database-for-ror/82390/3 "2006-03-16T00:19:12Z")

</div>

On 3/15/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What I am concerning about is the Id field in RoR and having it change  
> the datamodel. As other application are using it, is it possible to  
> have RoR integrate directly with an exisitng data schema without  
> changing it ? All the tutorials sort of do DB development when writing  
> the web application.

Yes, this is definitely possible. Check out the API docs on  
ActiveRecord[1], specifically the set\_primary\_key[2] class method.  
Example:

class Project \< ActiveRecord::Base  
set\_primary\_key “legacy\_id”  
end

Jacob F.

(PS. For future reference, these questions are much better directed at  
the Rails specific mailing list[3])

[1] [ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html)  
[2] [ActiveRecord::Base](http://api.rubyonrails.org/classes/ActiveRecord/Base.html#M000741)  
[3] [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [March 16, 2006, 12:25am UTC](https://www.ruby-forum.com/t/large-existing-database-for-ror/82390/4 "2006-03-16T00:25:15Z")

</div>

that is great Julain and Jacob!! I will have a go and get back if i  
have further questions!

Cheers
