Can I perform an INSERT-SELECT operation using the Rails API?

I need to duplicate a BLOB field from one table to another, and I want to use an INSERT-SELECT query to achieve this.

INSERT INTO target_table (key, data, comment) SELECT 'my key', data, 'some comment' FROM source_table 

Can this be done using the Rails API?

Of course, I could always use ActiveRecord::Base.connection to send my own request to the database, but I hope to find a β€œRails” way to do this. (One that is not related to actually loading data in my Rails application)

+6
ruby-on-rails ruby-on-rails-3
source share
1 answer

This is a typical scenario in which using SQL using ActiveRecord::Base.connection makes sense and sensitivity. There can be no path to it, as you described. Even if he was alone, he had to load it into memory and insert it into the target table with two models; This is madness.

+3
source share

All Articles