I’m using the ar-extensions gem to do bulk inserts in Rails 2.3.11 and wondering what the syntax is to insert ignore. If I just do:
User.import friends
Then I get duplicate key errors. I can try this:
User.import friends, :on_duplicate_key_update => [:first_name]
But if I don’t actually want to update it then there has to be some way to just do an INSERT IGNORE. Does anybody know the proper syntax for this?
So this is more of a workaround than a full answer, but it’s possible to make this work by simply avoiding adding model objects to the import array that already exist in the table. In relation to the example above, this can be achieved as follows. Let’s say we are populating friends by adding friend objects one by one:
We can avoid adding troublesome objects by simply doing: