Hi there,
I am trying to use rails with a legacy database setup, where some of the
tables use separate sequence tables to create id numbers rather than
using the autoincrement feature of the table itself.
Is there some way for me to point active record at these sequence tables
and have it continue numbering new ids from there?
I tried to use a direct sql query:
ActiveRecord::Base.connection.select_one(''select id+1 as id from
files_seq'')[''id'']
as part of the following file upload handler
@params[''record''][''name'']
@params[''record''][''tmp_file''].original_filename.gsub(/[^a-zA-Z0-9.]/,
''_'') # This makes sure filenames are sane
@params[''record''][''data'']
Base64::encode64(@params[''record''][''tmp_file''].read)
@params[''record''][''mimetype''] =
@params[''record''][''tmp_file''].content_type
@params[''record''][''id'']
ActiveRecord::Base.connection.select_one(''select id+1 as id from
files_seq'')[''id'']
@params[''record''][''last_modified_date''] =
Time.now
@params[''record''].delete(''tmp_file'') #
let''s remove the field from the
hash, because there''s no such field in the DB anyway.
@record = Record.new(@params[''record''])
but to no effect, the new record id was still 0. Of course ideally I
should be updating the files_seq table and getting the last insert id,
but I wanted to see if I could modify the id being inserted by ActiveRecord.
Any ideas on how to achieve this?
Many thanks in advance.
CHEERS> SAM