diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 524168f..7535a71 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -45,7 +45,7 @@ class OrdersController < ApplicationController def quickpay user = User.find(params[:user_id]) order = user.orders.build - order.products << user.dagschotel + order.order_items << OrderItem.new(count: 1, product: user.dagschotel, order: order) if order.save flash[:success] = "Quick pay succeeded. #{view_context.link_to("Undo", [user, order], method: :delete)}." else diff --git a/db/migrate/20150209144839_not_null_fields.rb b/db/migrate/20150209144839_not_null_fields.rb index 29ef396..34fc03f 100644 --- a/db/migrate/20150209144839_not_null_fields.rb +++ b/db/migrate/20150209144839_not_null_fields.rb @@ -1,6 +1,9 @@ class NotNullFields < ActiveRecord::Migration - def change + def up change_column :order_items, :product_id, :integer, null: false - change_column :order_items, :order_id, :integer, null: false + end + + def down + change_column :order_items, :product_id, :integer, null: true end end diff --git a/db/migrate/20150209145303_products_name_presence_true.rb b/db/migrate/20150209145303_products_name_presence_true.rb index f100f85..e9f518a 100644 --- a/db/migrate/20150209145303_products_name_presence_true.rb +++ b/db/migrate/20150209145303_products_name_presence_true.rb @@ -1,5 +1,9 @@ class ProductsNamePresenceTrue < ActiveRecord::Migration - def change + def up change_column :products, :name, :string, null: false end + + def down + change_column :products, :name, :string, null: true + end end diff --git a/db/migrate/20150210062809_order_id_null_allowed_in_order_items.rb b/db/migrate/20150210062809_order_id_null_allowed_in_order_items.rb new file mode 100644 index 0000000..91845b9 --- /dev/null +++ b/db/migrate/20150210062809_order_id_null_allowed_in_order_items.rb @@ -0,0 +1,9 @@ +class OrderIdNullAllowedInOrderItems < ActiveRecord::Migration + def up + change_column :order_items, :order_id, :integer, null: true + end + + def down + change_column :order_items, :order_id, :integer, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 510866b..47f2f07 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150209145303) do +ActiveRecord::Schema.define(version: 20150210062809) do create_table "order_items", force: true do |t| - t.integer "order_id", null: false + t.integer "order_id" t.integer "product_id", null: false t.integer "count", default: 0 end