module Elastictastic::ParentChild::ClassMethods

Attributes

parent_association[R]

Public Instance Methods

belongs_to(parent_name, options = {}) click to toggle source
# File lib/elastictastic/parent_child.rb, line 8
      def belongs_to(parent_name, options = {})
        @parent_association = Association.new(parent_name, options)

        module_eval(<<-RUBY, __FILE__, __LINE__+1)
          def #{parent_name}
            _parent
          end
        RUBY
      end
child_association(name) click to toggle source
# File lib/elastictastic/parent_child.rb, line 29
def child_association(name)
  child_associations[name.to_s]
end
child_associations() click to toggle source
# File lib/elastictastic/parent_child.rb, line 33
def child_associations
  @_child_associations ||= {}
end
has_many(children_name, options = {}) click to toggle source
# File lib/elastictastic/parent_child.rb, line 18
      def has_many(children_name, options = {})
        children_name = children_name.to_s
        child_associations[children_name] = Association.new(children_name, options)

        module_eval(<<-RUBY, __FILE__, __LINE__ + 1)
          def #{children_name}
            read_child(#{children_name.inspect})
          end
        RUBY
      end
mapping() click to toggle source
Calls superclass method
# File lib/elastictastic/parent_child.rb, line 37
def mapping
  super.tap do |mapping|
    mapping[type]['_parent'] = { 'type' => @parent_association.clazz.type } if @parent_association
  end
end