提交 b25e1800 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #25828 from bogdanvlviv/ref_default_sequence_name

Refactored method `ActiveRecord::ConnectionAdapters::PostgreSQL::SchemaStatements#default_sequence_name`. Refactored test `HasManyAssociationsTest#test_do_not_call_callbacks_for_delete_all`.
......@@ -327,12 +327,12 @@ def client_min_messages=(level)
end
# Returns the sequence name for a table's primary key or some other specified key.
def default_sequence_name(table_name, pk = nil) #:nodoc:
result = serial_sequence(table_name, pk || 'id')
def default_sequence_name(table_name, pk = 'id') #:nodoc:
result = serial_sequence(table_name, pk)
return nil unless result
Utils.extract_schema_qualified_name(result).to_s
rescue ActiveRecord::StatementInvalid
PostgreSQL::Name.new(nil, "#{table_name}_#{pk || 'id'}_seq").to_s
PostgreSQL::Name.new(nil, "#{table_name}_#{pk}_seq").to_s
end
def serial_sequence(table, column)
......
......@@ -244,8 +244,9 @@ def test_create_from_association_with_nil_values_should_work
def test_do_not_call_callbacks_for_delete_all
car = Car.create(:name => 'honda')
car.funky_bulbs.create!
assert_equal 1, car.funky_bulbs.count
assert_nothing_raised { car.reload.funky_bulbs.delete_all }
assert_equal 0, Bulb.count, "bulbs should have been deleted using :delete_all strategy"
assert_equal 0, car.funky_bulbs.count, "bulbs should have been deleted using :delete_all strategy"
end
def test_delete_all_on_association_is_the_same_as_not_loaded
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册