Created
October 3, 2013 08:03
-
-
Save avanishgiri/6806697 to your computer and use it in GitHub Desktop.
solutions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateProducts < ActiveRecord::Migration | |
| def change | |
| create_table :products do |t| | |
| t.string :title | |
| t.integer :seller_id | |
| t.timestamps | |
| end | |
| end | |
| end | |
| class CreateSellers < ActiveRecord::Migration | |
| def change | |
| create_table :sellers do |t| | |
| t.string :name | |
| t.decimal :balance | |
| t.decimal :total_sales | |
| t.timestamps | |
| end | |
| end | |
| end | |
| class CreatePurchases < ActiveRecord::Migration | |
| def change | |
| create_table :purchases do |t| | |
| t.decimal :amount | |
| t.boolean :already_paid | |
| t.integer :product_id | |
| t.timestamps | |
| end | |
| end | |
| end | |
| class AddIndexes < ActiveRecord::Migration | |
| def change | |
| add_index :products, :seller_id | |
| add_index :purchase, :product_id | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Seller < ActiveRecord::Base | |
| has_many :products | |
| has_many :purchases, :through => :products | |
| end | |
| class Product < ActiveRecord::Base | |
| belongs_to :seller | |
| has_many :purchases | |
| end | |
| class Purchase < ActiveRecord::Base | |
| belongs_to :product | |
| has_one :seller, :through => :product | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment