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
Methods inherited from Base
#as, #as?, #embeddable?, #foreign_key, #in_array?, #initialize, #ivar, #klass, #polymorphic?, #touch?, #type_key_name
Constructor Details
This class inherits a constructor from MongoMapper::Plugins::Associations::Base
Instance Method Details
#autosave? ⇒ Boolean
57 58 59 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 57 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 12 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mongo_mapper/plugins/associations/many_association.rb', line 28 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 association = self = self. model.before_destroy do if !association. 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 |