Skip to content

Commit 1db8402

Browse files
Minor optimization, removing unneeded variables (#546)
* Remove unused local variable delete dead code that became unused due to changes in commit 9937512 * group the assignment to the local variable in the same way as the assignment to association_foreign_key * move temporary variables, which are only referenced when association_class.paranoid? is true, inside the conditional branch * simplify association_find_conditions further --------- Co-authored-by: Mathieu Jobin <[email protected]>
1 parent 4db17c2 commit 1db8402

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

lib/paranoia.rb

+4-15
Original file line numberDiff line numberDiff line change
@@ -216,23 +216,12 @@ def restore_associated_records(recovery_window_range = nil)
216216
end
217217

218218
if association_data.nil? && association.macro.to_s == "has_one"
219-
association_class_name = association.klass.name
220-
221-
association_foreign_key = if association.options[:through].present?
222-
association.klass.primary_key
223-
else
224-
association.foreign_key
225-
end
226-
227-
if association.type
228-
association_polymorphic_type = association.type
229-
association_find_conditions = { association_polymorphic_type => self.class.name.to_s, association_foreign_key => self.id }
230-
else
231-
association_find_conditions = { association_foreign_key => self.id }
232-
end
233-
234219
association_class = association.klass
235220
if association_class.paranoid?
221+
association_foreign_key = association.options[:through].present? ? association.klass.primary_key : association.foreign_key
222+
association_find_conditions = { association_foreign_key => self.id }
223+
association_find_conditions[association.type] = self.class.name if association.type
224+
236225
association_class.only_deleted.where(association_find_conditions).first
237226
.try!(:restore, recursive: true, :recovery_window_range => recovery_window_range)
238227
end

0 commit comments

Comments
 (0)