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

Remove unused local variable and move local variables into conditional branch #546

Merged
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
19 changes: 4 additions & 15 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,12 @@ def restore_associated_records(recovery_window_range = nil)
end

if association_data.nil? && association.macro.to_s == "has_one"
association_class_name = association.klass.name

association_foreign_key = if association.options[:through].present?
association.klass.primary_key
else
association.foreign_key
end

if association.type
association_polymorphic_type = association.type
association_find_conditions = { association_polymorphic_type => self.class.name.to_s, association_foreign_key => self.id }
else
association_find_conditions = { association_foreign_key => self.id }
end

association_class = association.klass
if association_class.paranoid?
association_foreign_key = association.options[:through].present? ? association.klass.primary_key : association.foreign_key
association_find_conditions = { association_foreign_key => self.id }
association_find_conditions[association.type] = self.class.name if association.type

association_class.only_deleted.where(association_find_conditions).first
.try!(:restore, recursive: true, :recovery_window_range => recovery_window_range)
end
Expand Down