Module: MongoMapper::Associations::ClassMethods
- Defined in:
- lib/mongomapper/associations.rb
Instance Method Summary collapse
- #associations ⇒ Object
- #belongs_to(association_id, options = {}) ⇒ Object
- #many(association_id, options = {}) ⇒ Object
Instance Method Details
#associations ⇒ Object
35 36 37 |
# File 'lib/mongomapper/associations.rb', line 35 def associations @associations ||= HashWithIndifferentAccess.new end |
#belongs_to(association_id, options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mongomapper/associations.rb', line 4 def belongs_to(association_id, = {}) association = create_association(:belongs_to, association_id, ) ref_id = "#{association_id}_id" key ref_id, String define_method("#{ref_id}=") do |value| write_attribute(ref_id, value) end if [:polymorphic] ref_type = "#{association_id}_type" key ref_type, String define_method("#{ref_type}=") do |value| write_attribute(ref_type, value) end end define_association_methods(association) self end |
#many(association_id, options = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/mongomapper/associations.rb', line 28 def many(association_id, = {}) association = create_association(:many, association_id, ) define_association_methods(association) self end |