0

I am building a rails api application that connects to an existing oracle database

I have managed to create api's for the existing oracle tables using ruby-oci, oracle enhanced adapter and simple scaffolding, but how do I add all the pk, fk and index information to the models for each table?

2 Answers 2

1

I'm assuming that you have already setup your model and you have already setup the primary key as Mahatmanich said.

set.table_name="schema.table"
set.primary_key="legacy_id"

I also set aliases for all of my legacy table fields so that they are more readable within my code base.

alias :alias_name, :old_field_name

Usually with dealing with legacy databases the relationships aren't as straight forward as having a single primary key. Here are a few examples;

 belongs_to :the_other_table,
   :class_name => 'TheOtherClassName',
   :primary_key => 'key_in_other_table',
   :foreign_key => 'my_key'

 has_many :yet_another_tables,
   :class_name => "YetAnotherClassName",
   :primary_key => 'my_key_2', 
   :foreign_key => 'key_in_yet_another_table',
   :conditions => ['something = ?', true]
Sign up to request clarification or add additional context in comments.

Comments

0

Hi the best place to find this information is here: https://github.com/rsim/oracle-enhanced

Should be pretty straight forward, in your model do this:

class Test < ActiveRecord::Base
  self.table_name="Test"
  self.primary_key="id"
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.