Updating Fields In Migration for HABTM Relationship


#1

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


#2

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