daily pastebin goal
92%
SHARE
TWEET

Untitled

a guest Nov 21st, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MoveAuthorDataToAuthors < ActiveRecord::Migration
  2.  
  3.   def up
  4.     Book.all.each do |book|
  5.       first_name, last_name = book.author_name.split(' ')
  6.       Author.find_or_create_by(first_name: first_name, last_name: last_name).books << book
  7.     end
  8.   end
  9.  
  10.   def down
  11.     raise ActiveRecord::IrreversibleMigration
  12.   end
  13.  
  14. end
  15.    
  16. namespace :update_author_tabledb do
  17.   desc "Move Author Data To Authors"
  18.     Book.all.each do |book|
  19.       first_name, last_name = book.author_name.split(' ')
  20.       Author.find_or_create_by(first_name: first_name, last_name: last_name).books << book
  21.     end
  22.   end
  23. end
  24.    
  25. Book.all.each do |book|
  26.      first_name, last_name = book.author_name.split(' ')
  27.      Author.find_or_create_by(first_name: first_name, last_name: last_name).books << book
  28.  end
RAW Paste Data
Top