Skip to content

Commit 327f28b

Browse files
committed
Fix t.references validating options on Rails < 7.1
Option validation was [added][1] for 7.1+ Migration classes, and a compatibility layer was added to ensure that previous Migration versions do not have their options validated. However, the `t.references` method was missing in the compatibility layer which results in pre 7.1 Migrations validating options passed to `t.references`. This commit fixes the issue by adding t.references to the compatibility layer. See also a [similar fix][2] for `add_reference` [1]: e6da3eb [2]: 71b4e22
1 parent 299900f commit 327f28b

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

activerecord/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
* Fix Migrations with versions older than 7.1 validating options given to
2-
`add_reference`.
2+
`add_reference` and `t.references`.
33

44
*Hartley McGuire*
55

activerecord/lib/active_record/migration/compatibility.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def index(column_name, **options)
8282
super
8383
end
8484

85+
def references(*args, **options)
86+
options[:_skip_validate_options] = true
87+
super
88+
end
89+
8590
private
8691
def raise_on_if_exist_options(options)
8792
end

activerecord/test/cases/migration/compatibility_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ def migrate(x)
673673
change_table :tests do |t|
674674
t.change :some_id, :float, null: false, wrong_index: true
675675
t.integer :another_id, wrong_unique: true
676+
t.references :yet_another_table, bad: :option
676677
end
677678
end
678679
}.new

0 commit comments

Comments
 (0)