Skip to content

Commit 58aa3d3

Browse files
committed
Flatten sp_helpconstraint when looking for constraints just in case fks are present. Issue #64.
1 parent 0d34b79 commit 58aa3d3

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
* master *
33

4+
* Flatten sp_helpconstraint when looking for constraints just in case fks are present. Issue #64.
5+
46
* Start to support 2011 code named "Denali".
57

68
* Limit and Offset can take SqlLiteral objects now.

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@ def remove_check_constraints(table_name, column_name)
241241
end
242242
end
243243

244-
def remove_default_constraint(table_name, column_name)
245-
select_all("EXEC sp_helpconstraint '#{quote_string(table_name)}','nomsg'").select do |row|
244+
def remove_default_constraint(table_name, column_name))
245+
# If their are foreign keys in this table, we could still get back a 2D array, so flatten just in case.
246+
select_all("EXEC sp_helpconstraint '#{quote_string(table_name)}','nomsg'").flatten.select do |row|
246247
row['constraint_type'] == "DEFAULT on column #{column_name}"
247248
end.each do |row|
248249
do_execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{row['constraint_name']}"

0 commit comments

Comments
 (0)