Created
June 22, 2014 17:49
-
-
Save ryancheung/e16bbdc18165a242cb6e to your computer and use it in GitHub Desktop.
Generate insert sql using ActiveRecord(Rails 4)
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 characters
| record = User.new(username: 'ryan', email: 'ryan@hua.li') | |
| record.class.arel_table.create_insert.tap do |im| | |
| im.insert(record.send(:arel_attributes_with_values_for_create, record.attribute_names)) | |
| end.to_sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For reference if anyone else stumbles into this
For rails 5.2
I copied this from https://github.com/IFTTT/polo/pull/54/files