Class: MongoModel::Associations::HasManyByIds

Inherits:
Base::Definition show all
Defined in:
lib/mongomodel/concerns/associations/has_many_by_ids.rb

Defined Under Namespace

Classes: Association, Proxy

Instance Attribute Summary

Attributes inherited from Base::Definition

#name, #options, #owner

Instance Method Summary collapse

Methods inherited from Base::Definition

#collection?, #for, #initialize, #klass, methods, #polymorphic?, properties, #scope, #scope_options, #singular_name

Constructor Details

This class inherits a constructor from MongoModel::Associations::Base::Definition

Instance Method Details

#define!Object


8
9
10
11
12
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 8

def define!
  super
  define_dependency_callbacks!
  self
end

#define_dependency_callbacks!Object


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 14

def define_dependency_callbacks!
  association = self

  if options[:dependent] == :destroy
    owner.before_destroy do
      send(association.name).each { |child| child.destroy }
    end
  elsif options[:dependent] == :delete
    owner.before_destroy do
      send(association.name).delete_all
    end
  end
end

#property_nameObject


4
5
6
# File 'lib/mongomodel/concerns/associations/has_many_by_ids.rb', line 4

def property_name
  @property_name ||= :"#{singular_name}_ids"
end