module MongoModel::Associations::ClassMethods
Public Instance Methods
associations()
click to toggle source
# File lib/mongomodel/concerns/associations.rb, line 13 def associations @_associations ||= {} end
associations=(associations)
click to toggle source
# File lib/mongomodel/concerns/associations.rb, line 17 def associations=(associations) @_associations = associations end
belongs_to(name, options={})
click to toggle source
# File lib/mongomodel/concerns/associations.rb, line 21 def belongs_to(name, options={}) associations[name] = create_association(BelongsTo, name, options) end
has_many(name, options={})
click to toggle source
# File lib/mongomodel/concerns/associations.rb, line 25 def has_many(name, options={}) associations[name] = create_association(has_many_type(options), name, options) end
inherited(subclass)
click to toggle source
Calls superclass method
# File lib/mongomodel/concerns/associations.rb, line 29 def inherited(subclass) super subclass.associations = associations.dup end
Private Instance Methods
create_association(type, name, options={})
click to toggle source
# File lib/mongomodel/concerns/associations.rb, line 46 def create_association(type, name, options={}) type.new(self, name, options).define! end
has_many_type(options)
click to toggle source
# File lib/mongomodel/concerns/associations.rb, line 35 def has_many_type(options) case options[:by] when :ids HasManyByIds when :foreign_key HasManyByForeignKey else ancestors.include?(Document) ? HasManyByForeignKey : HasManyByIds end end