-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reproduce the rails 5.1 compatiability issue
Rails 5.1 and above add automatic validation for belongs_to association. It is enabled by an initializer added to new projects. Adding that configuartion in dummy app will reproduce the issue in test case
- Loading branch information
Showing
2 changed files
with
4 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ class ActivityLog < ActiveRecord::Base | |
self.table_name = :merit_activity_logs | ||
|
||
belongs_to :action, class_name: 'Merit::Action' | ||
belongs_to :related_change, polymorphic: true | ||
belongs_to :related_change, polymorphic: true, optional: true | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
tute
Member
|
||
has_one :sash, through: :related_change | ||
|
||
if show_attr_accessible? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if Rails.version >= "5.1" | ||
Rails.application.config.active_record.belongs_to_required_by_default = true | ||
end |
FYI, this seems to break Rails 4 since
optional
isn't a valid key there. Once I downloaded to Merit 3.0.1 it worked again.