mercredi 21 octobre 2015

ActiveRecord::RecordNotUnique when using update_attributes

I have a following problem:

Part of the code:

data.each do |row|
  record = profile.performance_data.find_or_initialize_by_date_and_channel_id_and_product_id(row[0].to_date, row[1].to_i, row[2].to_s)

  record.update_attributes(
    :field1 => row[3].to_s,
    :field2 => row[4].to_s
    #etc...
  )
end

And it works most of the time but sometimes throws ActiveRecord::RecordNotUnique

I have a unique index on four fields:

profile_id (which i get from profile object), date, channel_id and product_id

and im not modifying any of this fields in update_attributes() method

am I doing something wrong?

Aucun commentaire:

Enregistrer un commentaire