mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Skip eval relationships object on belongs to
This commit is contained in:
@@ -38,6 +38,10 @@ module ActiveModel
|
||||
reflection.options[:meta]
|
||||
end
|
||||
|
||||
def belongs_to?
|
||||
reflection.foreign_key_on == :self
|
||||
end
|
||||
|
||||
def polymorphic?
|
||||
true == reflection_options[:polymorphic]
|
||||
end
|
||||
|
||||
@@ -2,6 +2,10 @@ module ActiveModel
|
||||
class Serializer
|
||||
# @api private
|
||||
class BelongsToReflection < Reflection
|
||||
# @api private
|
||||
def foreign_key_on
|
||||
:self
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -47,11 +47,23 @@ module ActiveModel
|
||||
#
|
||||
# So you can inspect reflections in your Adapters.
|
||||
class Reflection < Field
|
||||
attr_reader :foreign_key, :type
|
||||
|
||||
def initialize(*)
|
||||
super
|
||||
options[:links] = {}
|
||||
options[:include_data_setting] = Serializer.config.include_data_default
|
||||
options[:meta] = nil
|
||||
@type = options.fetch(:type) do
|
||||
class_name = options.fetch(:class_name, name.to_s.camelize.singularize)
|
||||
class_name.underscore.pluralize.to_sym
|
||||
end
|
||||
@foreign_key =
|
||||
if collection?
|
||||
"#{name.to_s.singularize}_ids".to_sym
|
||||
else
|
||||
"#{name}_id".to_sym
|
||||
end
|
||||
end
|
||||
|
||||
# @api public
|
||||
@@ -150,6 +162,11 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
def foreign_key_on
|
||||
:related
|
||||
end
|
||||
|
||||
# Build association. This method is used internally to
|
||||
# build serializer's association by its reflection.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user