Class: MongoMapper::Plugins::Associations::ManyAssociation
- Defined in:
- lib/mongo_mapper/plugins/associations/many_association.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#name, #options, #query_options
Instance Method Summary collapse
- #autosave? ⇒ Boolean
- #class_name ⇒ Object
-
#proxy_class ⇒ Object
hate this, need to revisit.
- #setup(model) ⇒ Object
- #type_key_name ⇒ Object
Methods inherited from Base
#as, #as?, #embeddable?, #foreign_key, #in_array?, #initialize, #ivar, #klass, #polymorphic?
Constructor Details
This class inherits a constructor from MongoMapper::Plugins::Associations::Base
Instance Method Details
#autosave? ⇒ Boolean
61 62 63 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 61 def autosave? .fetch(:autosave, true) end |
#class_name ⇒ Object
7 8 9 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 7 def class_name @class_name ||= [:class_name] || name.to_s.singularize.camelize end |
#proxy_class ⇒ Object
hate this, need to revisit
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 16 def proxy_class @proxy_class ||= if klass. polymorphic? ? ManyEmbeddedPolymorphicProxy : ManyEmbeddedProxy else if polymorphic? ManyPolymorphicProxy elsif as? ManyDocumentsAsProxy elsif in_array? InArrayProxy else ManyDocumentsProxy end end end |
#setup(model) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 32 def setup(model) model.associations_module.module_eval <<-end_eval def #{name} get_proxy(associations[#{name.inspect}]) end def #{name}=(value) get_proxy(associations[#{name.inspect}]).replace(value) value end end_eval if [:dependent] && ! association = self = self. model.after_destroy do case [:dependent] when :destroy self.get_proxy(association).destroy_all when :delete_all self.get_proxy(association).delete_all when :nullify self.get_proxy(association).nullify end end end end |
#type_key_name ⇒ Object
11 12 13 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 11 def type_key_name "_type" end |