zdennis / ar-extensions

ActiveRecord::Extension (aka ar-extensions) is a plugin to extend and enhance the functionality of ActiveRecord
http://www.continuousthinking.com/tags/arext
225 stars 45 forks source link

:on_duplicate_key_update results in "PRIMARY KEY must be unique" #12

Open petercutting opened 14 years ago

petercutting commented 14 years ago

Hi I have imported data using ar_extensions 0.9.3 into sqlite 1.3.2 with impressive results. Now I want to process that data updating some fields in same table. The table has :id as primary key

  options = {:validate => false, :on_duplicate_key_update => [:x]}
  columns = [ :id,:x]
  igcfs = Igcfile.find(:all)  # get files
  igcfs.each do |igcf|    # for each file
    ps=[]
    igcps = igcf.igcpoint(:all, :order => 'seq_secs')   # get points
    igcps.each do |igcp|          # for each point

process data

      ps<<[igcp.id,igcp.x]         # push data to array
    end
    Igcpoint.import columns, ps, options   # update DB
  end

development.log sais - WARNING: Can't mass-assign these protected attributes: id

I see that this issue turned up a year ago. Not fixed yet? http://zdennis.lighthouseapp.com/projects/14379/tickets/26-cant-import-protected-attributes

If there is no fix then it looks like a workaroundmight be to create a 2nd unique key and use that instead of :id

Peter