Skip to content

Commit

Permalink
Remove last usage of _reflections in favor of reflect_on_association.
Browse files Browse the repository at this point in the history
- better compatible with newer Rails, since it casts to needed type on its own
  • Loading branch information
simi committed Sep 1, 2024
1 parent 1fa48c0 commit 87742cb
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def field_value
end

def reflection_class
has_polymorphic_association? ? polymorphic_class : @resource.model_class._reflections[@field.id.to_s].klass
has_polymorphic_association? ? polymorphic_class : @resource.model_class.reflect_on_association(@field.id).klass
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/components/avo/fields/has_one_field/show_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def can_see_the_create_button?
end

def create_path
association_id = @field.resource.model_class._reflections[@field.id.to_s].inverse_of.name
association_id = @field.resource.model_class.reflect_on_association(@field.id).inverse_of.name

args = {
via_relation: association_id,
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/avo/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def related_resource

return field.use_resource if field&.use_resource.present?

reflection = @model._reflections[params[:related_name]]
reflection = @model.class.reflect_on_association(params[:related_name])

reflected_model = reflection.klass

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def order
private

def set_reflection
@reflection = @model._reflections[params[:related_name].to_s]
@reflection = @model.class.reflect_on_association(params[:related_name])
end

def set_attachment_class
Expand All @@ -127,7 +127,7 @@ def attachment_id
end

def reflection_class
reflection = @model._reflections[params[:related_name]]
reflection = @model.class.reflect_on_association(params[:related_name])

klass = reflection.class.name.demodulize.to_s
klass = reflection.through_reflection.class.name.demodulize.to_s if klass == "ThroughReflection"
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def create

# This means that the record has been created through another parent record and we need to attach it somehow.
if params[:via_resource_id].present? && params[:via_belongs_to_resource_class].nil?
@reflection = @model._reflections[params[:via_relation]]
@reflection = @model.class.reflect_on_association(params[:via_relation])
# Figure out what kind of association does the record have with the parent record

# Fills in the required infor for belongs_to and has_many
Expand Down

0 comments on commit 87742cb

Please sign in to comment.