make fetch_associated_object a public method on relationship class so it can be called from SerilizationCore class

This commit is contained in:
Kyle Reeves 2018-07-02 10:56:52 -05:00 committed by Shishir Kakaraddi
parent 22d412246f
commit 6e7d8b7ee0
2 changed files with 6 additions and 11 deletions

View File

@ -37,6 +37,11 @@ module FastJsonapi
end
end
def fetch_associated_object(record, params)
return object_block.call(record, params) unless object_block.nil?
record.send(object_method_name)
end
private
def include_relationship?(record, serialization_params)
@ -80,11 +85,6 @@ module FastJsonapi
end
end
def fetch_associated_object(record, params)
return object_block.call(record, params) unless object_block.nil?
record.send(object_method_name)
end
def fetch_id(record, params)
unless object_block.nil?
object = object_block.call(record, params)

View File

@ -119,7 +119,7 @@ module FastJsonapi
serializer = relationship_item.serializer.to_s.constantize
relationship_type = relationship_item.relationship_type
included_objects = fetch_associated_object(record, relationship_item, params)
included_objects = relationship_item.fetch_associated_object(record, params)
next if included_objects.blank?
included_objects = [included_objects] unless relationship_type == :has_many
@ -138,11 +138,6 @@ module FastJsonapi
end
end
end
def fetch_associated_object(record, relationship, params)
return relationship.object_block.call(record, params) unless relationship.object_block.nil?
record.send(relationship.object_method_name)
end
end
end
end