Skip to content

Commit

Permalink
performance: use @reflection ivar on associations controller (#3076)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Jul 31, 2024
1 parent 4fab986 commit f4bb2e4
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def create_association
def destroy
association_name = BaseResource.valid_association_name(@record, @field.for_attribute || params[:related_name])

if reflection.instance_of? ActiveRecord::Reflection::ThroughReflection
if @reflection.instance_of? ActiveRecord::Reflection::ThroughReflection
join_record.destroy!
elsif has_many_reflection?
@record.send(association_name).delete @attachment_record
Expand Down Expand Up @@ -171,20 +171,16 @@ def association_from_params
@field&.for_attribute || params[:related_name]
end

def reflection
@record.class.reflections.with_indifferent_access[association_from_params]
end

def source_foreign_key
reflection.source_reflection.foreign_key
@reflection.source_reflection.foreign_key
end

def through_foreign_key
reflection.through_reflection.foreign_key
@reflection.through_reflection.foreign_key
end

def join_record
reflection.through_reflection.klass.find_by(source_foreign_key => @attachment_record.id,
@reflection.through_reflection.klass.find_by(source_foreign_key => @attachment_record.id,
through_foreign_key => @record.id)
end

Expand Down

0 comments on commit f4bb2e4

Please sign in to comment.