I have two tables. Table_1 has a 1 to many relationship with table_2. My goal is to move all the data in table_2 to a newly created text column in table_1, using a rails migration. I am to do the following in a migration using sqlite.
def up
sql = "UPDATE table_1 SET column=(SELECT name || ' ' || email FROM
table_2 WHERE table2.table_1_id=table_1.id)"
update (sql)
end
This works, but the problem is, each record in table_1 has 1 or more related records in table_2, how do I set the field in table_1 to all related records in table_2