module ActiveModel::Serializer::Associations::ClassMethods
Public Instance Methods
belongs_to(name, options = {}, &block)
click to toggle source
@param [Symbol] name of the association @param [Hash<Symbol => any>] options for the reflection @return [void]
@example
belongs_to :author, serializer: AuthorSerializer
# File lib/active_model/serializer/concerns/associations.rb, line 53 def belongs_to(name, options = {}, &block) associate(BelongsToReflection.new(name, options, block)) end
has_many(name, options = {}, &block)
click to toggle source
@param [Symbol] name of the association @param [Hash<Symbol => any>] options for the reflection @return [void]
@example
has_many :comments, serializer: CommentSummarySerializer
# File lib/active_model/serializer/concerns/associations.rb, line 42 def has_many(name, options = {}, &block) # rubocop:disable Style/PredicateName associate(HasManyReflection.new(name, options, block)) end
has_one(name, options = {}, &block)
click to toggle source
@param [Symbol] name of the association @param [Hash<Symbol => any>] options for the reflection @return [void]
@example
has_one :author, serializer: AuthorSerializer
# File lib/active_model/serializer/concerns/associations.rb, line 64 def has_one(name, options = {}, &block) # rubocop:disable Style/PredicateName associate(HasOneReflection.new(name, options, block)) end
inherited(base)
click to toggle source
Calls superclass method
# File lib/active_model/serializer/concerns/associations.rb, line 30 def inherited(base) super base._reflections = _reflections.dup end
Private Instance Methods
associate(reflection)
click to toggle source
Add reflection and define {name} accessor. @param [ActiveModel::Serializer::Reflection] reflection @return [void]
@api private
# File lib/active_model/serializer/concerns/associations.rb, line 76 def associate(reflection) key = reflection.options[:key] || reflection.name self._reflections[key] = reflection end