Module: RailsAdmin::Adapters::Mongoid::ObjectExtension

Defined in:
lib/rails_admin/adapters/mongoid/object_extension.rb

Class Method Summary collapse

Class Method Details

.extended(object) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_admin/adapters/mongoid/object_extension.rb', line 7

def self.extended(object)
  object.associations.each do |name, association|
    association = Association.new(association, object.class)
    case association.macro
    when :has_many
      unless association.autosave?
        object.singleton_class.after_create do
          send(name).each(&:save)
        end
      end
    when :has_one
      unless association.autosave?
        object.singleton_class.after_create do
          send(name)&.save
        end
      end
    end
  end
end