John Kopanas
2006-Jun-09 20:26 UTC
[Rails] Updating Fields In Migration for HABTM Relationship
Earlier I forgot to add updated_at and created_at columns for my HABTM relationship so I created a migration to add them. In the migration I also want to go back and set the value of the created_at and updated_at columns for the previous rows. What is the best way to do that? Initially I thought I was being smart and decided to put an UPDATE SQL query in a find_by_sql statement and then I could not deal with it''s uglyness. Any much wiser suggestions? John Kopanas http://www.kopanas.com ===========================================================http://www.soen.info - Index of online software engineering knowledge http://www.cusec.net - Canadian University Software Engineering Conference http://www.soenlive.com - Presentations from CUSEC
John Gray
2006-Jun-09 20:40 UTC
[Rails] Re: Updating Fields In Migration for HABTM Relationship
I don''t know whether this is the best way, but it''s the only way I know to do it with migrations. Use an exec statement to do things you can''t do with the migration interface. exec( ''UPDATE thetable SET updated_at = NOW()'' ) John Kopanas wrote:> Earlier I forgot to add updated_at and created_at columns for my > HABTM relationship so I created a migration to add them. In the > migration I also want to go back and set the value of the created_at > and updated_at columns for the previous rows. What is the best way > to do that? > > Initially I thought I was being smart and decided to put an UPDATE > SQL query in a find_by_sql statement and then I could not deal with > it''s uglyness. Any much wiser suggestions? > > John Kopanas > http://www.kopanas.com > > > ===========================================================> http://www.soen.info - Index of online software engineering knowledge > http://www.cusec.net - Canadian University Software Engineering > Conference > http://www.soenlive.com - Presentations from CUSEC-- Posted via http://www.ruby-forum.com/.