lib/avo/app/fields/has_many.rb in avo-0.4.2 vs lib/avo/app/fields/has_many.rb in avo-0.4.3
- old
+ new
@@ -4,10 +4,11 @@
def initialize(name, **args, &block)
@defaults = {
updatable: false,
component: 'has-many-field'
}
+ @through = args[:through]
super(name, **args, &block)
hide_on :index
@@ -25,10 +26,11 @@
target_resource = get_target_resource model
fields[:relation_class] = target_resource.class.to_s
fields[:path] = target_resource.url
fields[:relationship] = :has_many
+ fields[:through] = @through
fields[:relationship_model] = target_resource.model.name
fields
end
@@ -38,11 +40,11 @@
def get_target_resource(model)
if @resource.present?
App.get_resources.find { |r| r.class == @resource }
else
- class_name = model._reflections[id.to_s].options[:class_name].present? ? model._reflections[id.to_s].options[:class_name] : model._reflections[id.to_s].name
- App.get_resources.find { |r| r.class == "Avo::Resources::#{class_name.to_s.camelcase.singularize}".safe_constantize }
+ class_name = model._reflections[id.to_s].options[:class_name].present? ? model._reflections[id.to_s].options[:class_name] : model._reflections[id.to_s].klass.name
+ App.get_resource_by_model_name class_name
end
end
end
end
end