lib/avo/fields/belongs_to_field.rb in avo-2.27.2.pre.pr1606 vs lib/avo/fields/belongs_to_field.rb in avo-2.28.0

- old
+ new

@@ -55,10 +55,12 @@ # - foreign_key for poly type # - foreign_key for poly id # - is_disabled? class BelongsToField < BaseField + include Avo::Fields::Concerns::UseResource + attr_accessor :target attr_reader :polymorphic_as attr_reader :relation_method attr_reader :types # for Polymorphic associations @@ -77,10 +79,11 @@ @relation_method = id.to_s.parameterize.underscore @allow_via_detaching = args[:allow_via_detaching] == true @attach_scope = args[:attach_scope] @polymorphic_help = args[:polymorphic_help] @target = args[:target] + @use_resource = args[:use_resource] || nil end def searchable @searchable && ::Avo::App.license.has_with_trial(:searchable_associations) end @@ -220,9 +223,11 @@ rescue id end def target_resource + return use_resource if use_resource.present? + if is_polymorphic? if value.present? return App.get_resource_by_model_name(value.class) else return nil