Created
May 6, 2010 23:44
-
-
Save gisborne/392833 to your computer and use it in GitHub Desktop.
Revisions
-
gisborne created this gist
May 6, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ def self.create_from_array(attrs) keys = attrs.first.keys d = ActiveRecord::Base.connection d.execute <<SQL INSERT INTO #{table_name} (#{keys * ', '}, created_at, updated_at) VALUES #{attrs.map do |a| "(#{keys.map{|k| d.quote(a[k].to_s)} * ','}, NOW(), NOW())"} ON DUPLICATE KEY UPDATE #{keys.map{|k| "#{k} = VALUES(#{k})"} * ', '} SQL end