How can I insert multiple records into a database using rails syntax.
INSERT INTO users (email,name) VALUES ('[email protected]','a'),('[email protected]','b'),
('[email protected]','c');
This is how we do it in MySQL. How is this done in Rails?
While you cannot get the exact SQL that you have there, you can insert multiple records by passing create or new on an array of hashes:
new_records = [
{:column => 'value', :column2 => 'value'},
{:column => 'value', :column2 => 'value'}
]
MyModel.create(new_records)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With