-
Notifications
You must be signed in to change notification settings - Fork 897
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
Add has_many :miq_requests in ServiceTemplate #17242
Conversation
10d69f8
to
d89fae6
Compare
@miq-bot add_label transformation, enhancement |
app/models/service_template.rb
Outdated
@@ -55,6 +55,8 @@ class ServiceTemplate < ApplicationRecord | |||
|
|||
has_many :dialogs, -> { distinct }, :through => :resource_actions | |||
|
|||
has_many :miq_requests, ->(template) { where(["source_id = ? AND source_type = 'ServiceTemplate'", template.id]).order(:created_on) }, :foreign_key => "source_id" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is .order(:created_on)
really required here? I feel like this should be left to the caller to append if needed.
Also, does this need to be accessible from the API? cc @abellotti
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove the sorting. Was following examples from other model.
Checked with @abellotti. No changed is needed from API side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this as simple as has_many :miq_requests, :as => :source
?
http://guides.rubyonrails.org/association_basics.html#polymorphic-associations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this feels like revinventing Rails.
d89fae6
to
09c9ab3
Compare
@bzwei Can you take a look at the two rubocop issues. |
Can you put in 1 test to make sure the 2 models link together properly. Rubocop is complaining about:
I'm thinking you want: has_many :miq_requests, :as => :source, :dependent => :nullify maybe throw in |
09c9ab3
to
5cd8957
Compare
@kbrock Have the robot overloads officially taken over? Should we really be adding
|
@bzwei I am in favor of dropping As for tests, I would not expect you to test this association alone, but where this is used. What is the intended purpose of this change and can those changes be included in this PR and tested? |
5cd8957
to
2bd37e2
Compare
The purpose of the PR is for API to be able to include |
Checked commit bzwei@2bd37e2 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 app/models/service_template.rb
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Yeah, we generally avoid testing Rails things (like relations) since they're usually tested through many other paths.
Add has_many :miq_requests in ServiceTemplate (cherry picked from commit b452c96)
@miq-bot add_label gaprindashvili/yes Otherwise getting "Invalid attributes specified: miq_requests", when trying to retrieve a list of migration plans in v2v. (ManageIQ/manageiq-ui-classic#3963) (the request: |
Add has_many :miq_requests in ServiceTemplate (cherry picked from commit b452c96)
Gaprindashvili backport details:
|
Add
has_many :miq_requests
association inServiceTemplate
.It helps to find out all the
miq_requests
made from theservice_template