mercredi 16 novembre 2016

first_or_initialize is not working for relative model and creating new record each time

ccs.each do |cd|
  relative_model = main_model.relative_model.where(start_date: XYZ, end_date: XYZ).first_or_initialize
  relative_model.capacity = cd['capacity'].to_f
  relative_model.save!
end

As per above code, first_or_initialize is not working for relative model and creating new record each time.

NEED INITIAL HELP OR POINT OUT WHAT IS WRONG IN ABOVE CODE?

Aucun commentaire:

Enregistrer un commentaire