This commit is contained in:
ohsab 2014-11-25 16:16:21 +01:00
commit 7d082a64a7
7 changed files with 44 additions and 2 deletions

View file

@ -1,5 +1,8 @@
class Order < ActiveRecord::Base
belongs_to :users
has_many :order_products
has_many :products, through: :order_products
default_scope -> { order('created_at DESC') }
end

View file

@ -0,0 +1,4 @@
class OrderProduct < ActiveRecord::Base
belongs_to :order
belongs_to :product
end

View file

@ -0,0 +1,5 @@
class DropProductsOnUsers < ActiveRecord::Migration
def change
remove_column :orders, :products
end
end

View file

@ -0,0 +1,8 @@
class CreateOrderProducts < ActiveRecord::Migration
def change
create_table :order_products do |t|
t.belongs_to :order
t.belongs_to :product
end
end
end

View file

@ -11,11 +11,15 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141125102501) do
ActiveRecord::Schema.define(version: 20141125130447) do
create_table "order_products", force: true do |t|
t.integer "order_id"
t.integer "product_id"
end
create_table "orders", force: true do |t|
t.integer "user_id"
t.string "products"
t.integer "cost"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false

11
test/fixtures/order_products.yml vendored Normal file
View file

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View file

@ -0,0 +1,7 @@
require 'test_helper'
class OrderProductTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end