I am using a legacy database that uses one sequence for all the
tables in the system. There does not seem to be a way to support
this in Rails using Postgres.
I read in various places that you could use set_sequence_name is
your Rails models:
class ForumsForum < ActiveRecord::Base
set_primary_key :forum_id
set_sequence_name 't_acs_object_id_seq'
... end
However, Rails seems to completely ignore this directive for
Postgres. I think it does work for Oracle, but it really does not
seem to for Postgres.
Here's a unit test:
def test_save_message
forum = ForumsForum.new(:name => 'Test forum', <br/>
:charter => 'Test charter', \ :presentation_type => 'abc', \
:posting_policy => 'abc', \ :enabled_p => 'f') forum.save
... end
Here's the result of the test:
1) Error:
test_save_message(ForumsMessageTest):
ActiveRecord::StatementInvalid: PGError: ERROR: null value in
column "forum_id" violates not-null constraint
: INSERT INTO "forums_forums" ("name", "package_id", "last_post",
"thread_count", "approved_thread_count", "max_child_sortkey",
"charter", "posting_policy", "presentation_type", "enabled_p")
VALUES(E'Test forum', NULL, NULL, 0, 0, NULL, E'Test charter',
E'abc', E'abc', E'f') RETURNING "forum_id"
test/unit/forums_message_test.rb:20:in
test_save_message'
1 tests, 0 assertions, 0 failures, 1 errors
Note the RETURNING statement. All variations I tried to
set_sequence_name did not work. After a little looking, I saw
this:
http://www.ruby-forum.com/topic/81873
And looking into the Rails source code, at first glance it does
appear that the sequence name is not honored.