lib/avo/fields/belongs_to_field.rb in avo-3.4.1 vs lib/avo/fields/belongs_to_field.rb in avo-3.4.2
- old
+ new
@@ -117,11 +117,11 @@
resource = Avo.resource_manager.get_resource_by_model_class model if model.present?
query = resource.query_scope
if attach_scope.present?
- query = Avo::ExecutionContext.new(target: attach_scope, query: query, parent: get_model).handle
+ query = Avo::ExecutionContext.new(target: attach_scope, query: query, parent: get_record).handle
end
query.all.map do |record|
[resource.new(record: record).record_title, record.id]
end
@@ -162,11 +162,11 @@
@resource.model_class.reflections[@relation_method].foreign_key
end
end
def reflection_for_key(key)
- get_model_class(get_model).reflections[key.to_s]
+ get_model_class(get_record).reflections[key.to_s]
rescue
nil
end
# Get the model reflection instance
@@ -249,16 +249,12 @@
else
App.get_resource_by_name reflection_key.to_s
end
end
- def get_model
- return @record if @record.present?
-
- @resource.record
- rescue
- nil
+ def get_record
+ @record || @resource.record
end
def default_name
return polymorphic_as.to_s.humanize if polymorphic_as.present?
@@ -269,14 +265,16 @@
@can_create
end
private
- def get_model_class(model)
- if model.instance_of?(Class)
- model
+ def get_model_class(record)
+ if record.nil?
+ @resource.model_class
+ elsif record.instance_of?(Class)
+ record
else
- model.class
+ record.class
end
end
end
end
end