No API documentation for ActiveRecord#connection.execute method
Reported by Jim Gagne | July 12th, 2007 @ 08:56 PM
In importing legacy databases, it can be helpful to go behind ActiveRecord’s back and work directly through MySQL. But there’s little or no documentation of the Model.connection.execute(“[SQL statement]”) method, and NO description of the syntax: it’s a class method
For example, Model.delete_all empties the table, but autoincrementing fields like :id keep on incrementing from whatever number they were on. Model.connection.execute(“TRUNCATE TABLE models”) effectively deletes the table and recreates it with all counters reset. This would prevent :id integer overflow if one kept reimporting a large table.
Other SQL statements could be used to generate :id fields from existing legacy table key fields not in integer format. That way, one doesn’t have to dig through the entire imported database to look up valid foreign key links: calculate them instead. (According to the Agile Web Development book, Rails can’t save a record unless the :id field is valid, so generating a new :id field appears to be verboten.)
Comments and changes to this ticket
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
