Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

No API documentation for ActiveRecord#connection.execute method

#4

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.)

Reported by Jim Gagne · July 12th, 2007 @ 08:56 PM

State: new
Milestone: none
Assigned to: nobody

Activity

No comments yet.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.