SEQUENCES are supported in RAILS via PolymorphicAssociations
And that is all you need to know.
BUT, see also:
there was a change in Rails 1.13.2 “PostgreSQL: correctly discover custom primary key sequences.”
some more information:
http://blog.evanweaver.com/articles/2006/06/06/polymorphic-association-helpers
http://www.robbyonrails.com/articles/2005/08/20/postgresql-sequences-in-rails
http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through
Dealing with legacy sequences in ActiveRecord:
I had a legacy postgres database that had sequences for creating the primary keys on some of the tables. These tables weren’t setup with the sequences as a default value for the primary key.. the legacy code prefetched the next sequence value then inserted a record with that ID. Looking at active record, it seemed like it should be a snap to reproduce the same functionality.
This is what I ended up with:
(replace the table names “address” and “user_profile” with your own). If you need prefetching on all your tables, just return true from “prefetch_primary_key?”.
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
def prefetch_primary_key?(table_name = nil)
table_name && %w{address user_profile}.member?(table_name)
end
def next_sequence_value(sequence_name)
Integer(select_value("SELECT nextval('#{sequence_name}')"))
end
end
end
end
class UserProfile < ActiveRecord::Base
set_table_name "user_profile"
set_primary_key "user_id"
set_sequence_name "useridsequence"
belongs_to :address
end
class Address < ActiveRecord::Base
set_table_name "address"
set_primary_key "address_id"
set_sequence_name "addressidsequence"
has_one :user_profile
end