Module: MmPartialUpdate::EmbeddedCollection

Defined in:
lib/mm_partial_update/embedded_collection.rb

Instance Method Summary collapse

Instance Method Details

#add_updates_to_command(changes, command) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mm_partial_update/embedded_collection.rb', line 8

def add_updates_to_command(changes, command)
  selector = association.name
  selector = "#{proxy_owner.database_selector}.#{selector}" if
    proxy_owner.respond_to?(:database_selector)

  unless changes.blank?
    deleted = changes[0] - changes[1]
    deleted.each { |d| command.pull(selector, d._id) }
  end

  unless @target.blank?
    @target.each do |child|
      child.new? ? command.push(selector, child.to_mongo) :
        child.add_updates_to_command(command)
    end
  end

end

#save_to_collection(options) ⇒ Object



4
5
6
# File 'lib/mm_partial_update/embedded_collection.rb', line 4

def save_to_collection(options)
  super.tap { assign_database_indexes }
end