xvpafa
Last Updated: January 17, 2017
·
1.625K
· mwalsher
5b4dd0c0b7dc207136cb7f0eecffce64

Rails check if has_many changed

class Company < ActiveRecord::Base
  has_many :employees
  accepts_nested_attributes_for :employees

  def employees_changed?
    employees.select { |e| e.new_record? || e.marked_for_destruction? }.any?
  end
end
Say Thanks
Respond

1 Response
Add your response

28510
D5812bf6d9e25a2d219df9e5f6c9b97b

How about this?

employees.any? { |e| e.new_record? || e.marked_for_destruction? }

over 1 year ago ·