Skip eval relationships object on belongs to

This commit is contained in:
Benjamin Fleischer
2017-04-30 18:31:35 -05:00
parent 273b7e7f30
commit 6e41528515
5 changed files with 46 additions and 7 deletions

View File

@@ -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

View File

@@ -2,6 +2,10 @@ module ActiveModel
class Serializer
# @api private
class BelongsToReflection < Reflection
# @api private
def foreign_key_on
:self
end
end
end
end

View File

@@ -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.
#