Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
record = => 'Yay', :body => 'This is some insert SQL')
# easiest way to achieve this is by calling protected #arel_attributes_values (tested in
# rails 3.2.13). the alternative is to build the entire insert statement using arel >_>
record.class.arel_table.create_insert \
.tap { |im| im.insert(record.send(:arel_attributes_values, false)) } \
Copy link

formigarafa commented Feb 22, 2016

thanks, and: Or for Rails 4

record = => 'Yay', :body => 'This is some insert SQL')

record.class.arel_table.create_insert. \
  tap { |im| 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment