ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:host =>"localhost",
:username => "test",
:password => "",
:database => "project_development"
)
class Account < ActiveRecord::Base
set_sequence_name "account_seq"
set_primary_key :id
end
account = Account.new
account.username = "User1"
account.save
-----
Task: I want use postgresql sequence for generation of primary key.
I use 'set_sequence_name', but this don't work.
Question: How to make active use of the active record of the sequence
to generate a primary key?
--
Posted via http://www.ruby-forum.com/.
Task: I want use postgresql sequence for generation of primary key.
I use 'set_sequence_name', but this don't work.
I want that active record invoke sequence and insert new primary key to
id property.
CREATE SEQUENCE account_seq
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
----
But active record don't use account_seq again :(.
I don't know the full answer, but I think you may have to use
set_primary_key in your model. Google for rails legacy database and
you may find some helpful links.
Colin