Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fixes #16172 - remove base_class override in template subclasses
On Rails 5.0, the base_class is used during model instantiation to validate STI relationships as it now casts similarly to Foreman::STI, causing failures when base_class returns the subclass rather than parent class. Removing the overriding of `base_class` in Template subclasses necessitates changing polymorphic associations to store the base class in the table's type field rather than the subclass name because the has_many associations will search by `base_class`. This is recommended by ActiveRecord when using STI with polymorphic associations: https://github.com/rails/rails/blob/v5.0.0/activerecord/lib/active_record/associations.rb#L780
- Loading branch information
Showing
10 changed files
with
46 additions
and
26 deletions.
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
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
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
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
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
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
12 changes: 12 additions & 0 deletions
12
db/migrate/20160719095445_change_template_taxable_taxonomies_type.rb
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,12 @@ | ||
| class ChangeTemplateTaxableTaxonomiesType < ActiveRecord::Migration | ||
| def up | ||
| known_types = Template.descendants.map(&:to_s) | ||
| TaxableTaxonomy.where(:taxable_type => known_types).update_all(:taxable_type => 'Template') | ||
| end | ||
|
|
||
| def down | ||
| Template.descendants.each do |type| | ||
| TaxableTaxonomy.where(:taxable_type => 'Template', :taxable_id => type.pluck(:id)).update_all(:taxable_type => type.to_s) | ||
| end | ||
| end | ||
| end |
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,14 @@ | ||
| class ChangeTemplateAuditsType < ActiveRecord::Migration | ||
| def up | ||
| known_types = Template.descendants.map(&:to_s) | ||
| Audit.where(:auditable_type => known_types).update_all(:auditable_type => 'Template') | ||
| Audit.where(:associated_type => known_types).update_all(:associated_type => 'Template') | ||
| end | ||
|
|
||
| def down | ||
| Template.descendants.each do |type| | ||
| Audit.where(:auditable_type => 'Template', :auditable_id => type.pluck(:id)).update_all(:auditable_type => type.to_s) | ||
| Audit.where(:associated_type => 'Template', :associated_id => type.pluck(:id)).update_all(:associated_type => type.to_s) | ||
| end | ||
| end | ||
| end |
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
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