aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-24 14:01:35 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-24 14:01:35 +0000
commit14ea312808599001674784a839bf7cf5a8eea872 (patch)
tree9875456d3eba2ceb2f86909ee280333e2dfefa94 /activerecord/lib/active_record/base.rb
parent1ae0a53d861c43dff8883fc956a08404c23f180c (diff)
downloadrails-14ea312808599001674784a839bf7cf5a8eea872.tar.gz
rails-14ea312808599001674784a839bf7cf5a8eea872.tar.bz2
rails-14ea312808599001674784a839bf7cf5a8eea872.zip
Made Oracle a first-class connection adapter by adhering closer to idiomatic Oracle style #1798 [The Gang of Oracles]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1912 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 20ccd9a623..84bf0cdcff 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -569,6 +569,11 @@ module ActiveRecord #:nodoc:
"type"
end
+ # Defines the sequence_name (for Oracle) -- can be overridden in subclasses.
+ def sequence_name
+ "#{table_name}_seq"
+ end
+
# Sets the table name to use to the given value, or (if the value
# is nil or false) to the value returned by the given block.
#
@@ -612,6 +617,25 @@ module ActiveRecord #:nodoc:
end
alias :inheritance_column= :set_inheritance_column
+ # Sets the name of the sequence to use when generating ids to the given
+ # value, or (if the value is nil or false) to the value returned by the
+ # given block. Currently useful only when using Oracle, which requires
+ # explicit sequences.
+ #
+ # Setting the sequence name when using other dbs will have no effect.
+ # If a sequence name is not explicitly set when using Oracle, it will
+ # default to the commonly used pattern of: #{table_name}_seq
+ #
+ # Example:
+ #
+ # class Project < ActiveRecord::Base
+ # set_sequence_name "projectseq" # default would have been "project_seq"
+ # end
+ def set_sequence_name( value=nil, &block )
+ define_attr_method :sequence_name, value, &block
+ end
+ alias :sequence_name= :set_sequence_name
+
# Turns the +table_name+ back into a class name following the reverse rules of +table_name+.
def class_name(table_name = table_name) # :nodoc:
# remove any prefix and/or suffix from the table name
@@ -1193,7 +1217,7 @@ module ActiveRecord #:nodoc:
"(#{quoted_column_names.join(', ')}) " +
"VALUES(#{attributes_with_quotes.values.join(', ')})",
"#{self.class.name} Create",
- self.class.primary_key, self.id
+ self.class.primary_key, self.id, self.class.sequence_name
)
@new_record = false