Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 5.0/5.1 compatibility: Define through association before has many through #18080

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/models/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Storage < ApplicationRecord
has_many :storage_files, :dependent => :destroy
has_many :storage_files_files, -> { where("rsc_type = 'file'") }, :class_name => "StorageFile", :foreign_key => "storage_id"
has_many :files, -> { where("rsc_type = 'file'") }, :class_name => "StorageFile", :foreign_key => "storage_id"
has_many :host_storages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this doing here? Seems unrelated to the original PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, let me explain. There's two host_storages has_manys. One on line line 5 and one here, at line 21. Because this one on line 21 is "last", it wins. This causes a problem because line 6, we have:

has_many :hosts, :through => :host_storages

This causes complaints on rails 5.1 because the through association is needed before it's defined.


has_many :miq_events, :as => :target, :dependent => :destroy

Expand Down
2 changes: 1 addition & 1 deletion app/models/vm.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Vm < VmOrTemplate
default_scope { where(:template => false) }
has_one :container_deployment, :through => :container_deployment_node
has_one :container_deployment_node
has_one :container_deployment, :through => :container_deployment_node

virtual_has_one :supported_consoles, :class_name => "Hash"

Expand Down