Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MoveAuthorDataToAuthors < ActiveRecord::Migration
- def up
- Book.all.each do |book|
- first_name, last_name = book.author_name.split(' ')
- Author.find_or_create_by(first_name: first_name, last_name: last_name).books << book
- end
- end
- def down
- raise ActiveRecord::IrreversibleMigration
- end
- end
- namespace :update_author_tabledb do
- desc "Move Author Data To Authors"
- Book.all.each do |book|
- first_name, last_name = book.author_name.split(' ')
- Author.find_or_create_by(first_name: first_name, last_name: last_name).books << book
- end
- end
- end
- Book.all.each do |book|
- first_name, last_name = book.author_name.split(' ')
- Author.find_or_create_by(first_name: first_name, last_name: last_name).books << book
- end
Add Comment
Please, Sign In to add comment