1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #24292 from arthurnn/arthurnn/pk_sequence_klass

Move sequence value methods to Model level
This commit is contained in:
Arthur Nogueira Neves 2016-03-24 17:17:10 -04:00
commit a12ad8ae54
2 changed files with 14 additions and 2 deletions

View file

@ -231,6 +231,18 @@ module ActiveRecord
@explicit_sequence_name = true
end
# Determines if the primary key values should be selected from their
# corresponding sequence before the insert statement.
def prefetch_primary_key?
connection.prefetch_primary_key?(table_name)
end
# Returns the next value that will be used as the primary key on
# an insert statment.
def next_sequence_value
connection.next_sequence_value(sequence_name)
end
# Indicates whether the table associated with this class exists
def table_exists?
connection.schema_cache.data_source_exists?(table_name)

View file

@ -45,8 +45,8 @@ module ActiveRecord
k.name == primary_key
}]
if !primary_key_value && connection.prefetch_primary_key?(klass.table_name)
primary_key_value = connection.next_sequence_value(klass.sequence_name)
if !primary_key_value && klass.prefetch_primary_key?
primary_key_value = klass.next_sequence_value
values[arel_attribute(klass.primary_key)] = primary_key_value
end
end