class employee ... def product_ids_=(ids) return if id.to_s == '' Assignment.delete_all("assignment_type = 'EmployeeProduct' and employee_id = #{id}") ids.each do |i| self.assignments << EmployeeProduct.new(:entity_id => i, :employee_id => self.id) if i.to_s != '' end end ... end