Reputation: 4065
I need to move some user info from one db table to another.
From User to brands_users.
I want to move user_id and brand_id to brands_users - how do I do that?
How do i save data to a HABTM DB table?
Thanks
Upvotes: 0
Views: 3449
Reputation: 8807
Assumptions:
Write a script which will read users table and create records in the brands_users table
class BrandsUser << AR::Base
belongs_to :user
belongs_to :brand
end
require 'rubygems'
User.each do |u|
bs = BrandsUser.new(
:user_id => u.id,
:brand_id => u.brand_id
)
bs.save
end
Run the script using rails runner
rails runner db/scripts/data_mover.rb
Upvotes: 4