Module: Elastictastic::ParentChild::ClassMethods
- Defined in:
- lib/elastictastic/parent_child.rb
Instance Attribute Summary collapse
-
#parent_association ⇒ Object
readonly
Returns the value of attribute parent_association.
Instance Method Summary collapse
- #belongs_to(parent_name, options = {}) ⇒ Object
- #child_association(name) ⇒ Object
- #child_associations ⇒ Object
- #has_many(children_name, options = {}) ⇒ Object
- #mapping ⇒ Object
Instance Attribute Details
#parent_association ⇒ Object (readonly)
Returns the value of attribute parent_association.
6 7 8 |
# File 'lib/elastictastic/parent_child.rb', line 6 def parent_association @parent_association end |
Instance Method Details
#belongs_to(parent_name, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/elastictastic/parent_child.rb', line 8 def belongs_to(parent_name, = {}) @parent_association = Association.new(parent_name, ) module_eval(<<-RUBY, __FILE__, __LINE__+1) def #{parent_name} _parent end RUBY end |
#child_association(name) ⇒ Object
29 30 31 |
# File 'lib/elastictastic/parent_child.rb', line 29 def child_association(name) child_associations[name.to_s] end |
#child_associations ⇒ Object
33 34 35 |
# File 'lib/elastictastic/parent_child.rb', line 33 def child_associations @_child_associations ||= {} end |
#has_many(children_name, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/elastictastic/parent_child.rb', line 18 def has_many(children_name, = {}) children_name = children_name.to_s child_associations[children_name] = Association.new(children_name, ) module_eval(<<-RUBY, __FILE__, __LINE__ + 1) def #{children_name} read_child(#{children_name.inspect}) end RUBY end |
#mapping ⇒ Object
37 38 39 40 41 |
# 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 |