Module: Caprese::Serializer::Relationships

Extended by:
ActiveSupport::Concern
Included in:
Caprese::Serializer
Defined in:
lib/caprese/serializer/concerns/relationships.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#relationship_scope(name, scope) ⇒ Object

Note:

Can be overridden to customize scoping at a per-relationship level

Applies further scopes to a singular or collection association when rendered as part of included document

Examples:

def relationship_scope(name, scope)
  case name
  when :transactions
    scope.by_merchant(...)
  when :orders
    scope.by_user(...)
  when :user
    # change singular user response
  end
end

Parameters:

  • name (String)

    the name of the association

  • scope (Relation, Record)

    the scope corresponding to a collection association relation or singular record



25
26
27
# File 'lib/caprese/serializer/concerns/relationships.rb', line 25

def relationship_scope(name, scope)
  scope
end