Module: ActiveRecord::ActsHasMany::ChildThrough

Defined in:
lib/acts_has_many/active_record/acts_has_many/child.rb

Instance Method Summary collapse

Instance Method Details

#has_many_through_update(options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/acts_has_many/active_record/acts_has_many/child.rb', line 38

def has_many_through_update(options)
  record_add = []
  record_del = []

  options[:update].each do |id, data|
    add, del = find(id).has_many_update data
    record_add << add unless add.nil?
    record_del << del unless del.nil?
  end unless options[:update].nil?

  unless options[:new].nil?
    options[:new].uniq!
    options[:new].each do |data|
      record_add << new.has_many_update(data).first
      record_del.delete record_add.last
    end
  end

  [record_add, record_del]
end