Module: Mongo::Model::FileModel::ClassMethods

Defined in:
lib/mongo/model/file_model.rb

Instance Method Summary collapse

Instance Method Details

#mount_file(attr_name, file_model_class) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mongo/model/file_model.rb', line 13

def mount_file attr_name, file_model_class
  super

  before_validate do |model|
    file_model = model.send(attr_name)
    file_model.run_validations
    model.errors[attr_name] = file_model.errors unless file_model.errors.empty?
  end

  after_save{|model| model.send(attr_name).save}

  after_destroy{|model| model.send(attr_name).destroy}
end