class CreatePProductImages < ActiveRecord::Migration
  def change
    create_table :p_product_images do |t|
      t.string :title
      t.text :description
      t.integer :position
      t.references :image_file, index: false
      t.references :p_product, index: false

      t.timestamps null: false
      
      
    end
    
    PProduct.all.each do |pp|
      if pp.image_file
        pp.p_product_images.create(:image_file_id => pp.image_file_id, :position => 1)
        
      end
    end

    #add_foreign_key :product_images, :image_files
  end
end
