diff --git a/lib/avo/base_resource.rb b/lib/avo/base_resource.rb index 956bcfbe97..2abb8371e6 100644 --- a/lib/avo/base_resource.rb +++ b/lib/avo/base_resource.rb @@ -114,7 +114,7 @@ def order_actions end def get_record_associations(record) - record._reflections + record.class.reflections end def valid_association_name(record, association_name) @@ -382,7 +382,7 @@ def hydrate_model_with_default_values if field.type == "belongs_to" - reflection = @model._reflections[@params[:via_relation]] + reflection = @model.class.reflections[@params[:via_relation]] if field.polymorphic_as.present? && field.types.map(&:to_s).include?(@params[:via_relation_class]) # set the value to the actual record diff --git a/lib/avo/fields/belongs_to_field.rb b/lib/avo/fields/belongs_to_field.rb index 1513d6cf41..76bfe47e4e 100644 --- a/lib/avo/fields/belongs_to_field.rb +++ b/lib/avo/fields/belongs_to_field.rb @@ -245,10 +245,10 @@ def target_resource reflection_key = polymorphic_as || id - if @model._reflections[reflection_key.to_s].klass.present? - App.get_resource_by_model_name @model._reflections[reflection_key.to_s].klass.to_s - elsif @model._reflections[reflection_key.to_s].options[:class_name].present? - App.get_resource_by_model_name @model._reflections[reflection_key.to_s].options[:class_name] + if @model.class.reflections[reflection_key.to_s].klass.present? + App.get_resource_by_model_name @model.class.reflections[reflection_key.to_s].klass.to_s + elsif @model.class.reflections[reflection_key.to_s].options[:class_name].present? + App.get_resource_by_model_name @model.class.reflections[reflection_key.to_s].options[:class_name] else App.get_resource_by_name reflection_key.to_s end diff --git a/lib/avo/fields/has_base_field.rb b/lib/avo/fields/has_base_field.rb index c63378007f..4a63446ebd 100644 --- a/lib/avo/fields/has_base_field.rb +++ b/lib/avo/fields/has_base_field.rb @@ -59,10 +59,10 @@ def field_label end def target_resource - if @model._reflections[id.to_s].klass.present? - Avo::App.get_resource_by_model_name @model._reflections[id.to_s].klass.to_s - elsif @model._reflections[id.to_s].options[:class_name].present? - Avo::App.get_resource_by_model_name @model._reflections[id.to_s].options[:class_name] + if @model.class.reflections[id.to_s].klass.present? + Avo::App.get_resource_by_model_name @model.class.reflections[id.to_s].klass.to_s + elsif @model.class.reflections[id.to_s].options[:class_name].present? + Avo::App.get_resource_by_model_name @model.class.reflections[id.to_s].options[:class_name] else Avo::App.get_resource_by_name id.to_s end