Forum: Ruby on Rails Legacy DB and id issue

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.
10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2009-05-23 03:13
(Received via mailing list)
ruby: 1.8.6
rails: 2.3.2
Database: Oracle 10g

Table with fields:
  ID varchar2(6)
  REC_NO number(10,0)
  (No primary key declaration)

Model:
  class Myclass < ActiveRecord::Base
    self.primary_key = 'rec_no'
    self.sequence_name = 's_rn_mytable'
  end

As you can see as described in the model there is a sequence in the DB
that generates a unique number.

REC_NO is being used as "primary key" and should be receiving the
unique generated value.

ID is used to store values (not unique) from another table.

When a record is created the value of ID is always nil with the model
above. If I change the primary key description in the model and
specify the column ID (self.primary_key = 'id') I can assign values to
ID (although a varchar column the stored numbers are numeric so it
lets me do it) but then REC_NO gets the value nil.

Is there a way to make this work the 'rails' way? I'd rather not use
SQL, which allows me to create the records the way I need.

Thanks a lot.

Pepe
10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2009-05-23 05:40
(Received via mailing list)
Corrections:

If I change the primary key description in the model and specify the
column ID (self.primary_key = 'id') I can assign values to ID, the
model shows the values I entered but they are overridden anyway by the
DB.

Pepe
This topic is locked and can not be replied to.