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

performance: use @reflection ivar on associations controller #3076

Merged
merged 1 commit into from
Jul 31, 2024
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
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
Loading