Duplicate entry mystery

I have a rails app that has a sync feature which looks up a remote
database and
updates the local database accordingly. Anyway, things work great for
the most
part, but there is a section of code which seems to randomly raise
errors. I
have something like this:

homelinks = Syncinventorydesc.find(:all)

InventoryDescription.delete_all()

for link in homelinks

 locallink = InventoryDescription.new()

 locallink.inventory_id = link.inventory_id
 locallink.description_id = link.description_id

 locallink.save!

end

this code tears down the local table completely before going through
each item
fetched on the remote db and inserting them in. Every now and then i get
the
duplicate error message (there a no duplicate keys in the original
table), which
suggests that either not all records are getting wiped out of the local
table OR
a record is getting saved twice somehow… both seem very unlikely.

i have wrapped the locallink.save! in a rescue block to let the
exception slide
which should silence this problem, but the mystery remains. Anybody know
what’s
up? Thanks

Stuart

Thanks

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs