Skip to content

Commit

Permalink
Use o.reload.assoc, assoc(true) is gone
Browse files Browse the repository at this point in the history
Note, the before_save was calling remove_invalid_resource on create
which didn't make sense because it was trying to find service_resources
with orphaned resources, which can't happen unless the service_template
itself has been saved.  Because of this, it makes sense to change this
to before_update instead of adding r.persisted? checks in the
remove_invalid_resource method.

The force reload parameter was removed from associations in:
rails/rails@09cac8c67af

It was previously deprecated here:
rails/rails@6eae366

From that commit:

For collections:
@user.posts.reload   # Instead of @user.posts(true)

For singular associations:
@user.reload.profile # Instead of @user.profile(true)

Extracted from #18076
  • Loading branch information
jrafanie committed Oct 11, 2018
1 parent 520f007 commit 3f4f8c6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/service_template_ansible_tower.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ServiceTemplateAnsibleTower < ServiceTemplate
include ServiceConfigurationMixin

before_save :remove_invalid_resource
before_update :remove_invalid_resource

alias job_template configuration_script
alias job_template= configuration_script=
Expand All @@ -24,7 +24,7 @@ def self.create_catalog_item(options, _auth_user = nil)

def remove_invalid_resource
# remove the resource from both memory and table
service_resources.to_a.delete_if { |r| r.destroy unless r.resource(true) }
service_resources.to_a.delete_if { |r| r.destroy unless r.reload.resource.present? }
end

def create_subtasks(_parent_service_task, _parent_service)
Expand Down

0 comments on commit 3f4f8c6

Please sign in to comment.