Created
November 6, 2015 19:17
-
-
Save ajosanchez/931f1c75acadff746e6a to your computer and use it in GitHub Desktop.
This file contains 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
require 'sqlite3' | |
require 'active_record' | |
ActiveRecord::Base.logger = Logger.new(STDERR) | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'sqlite3', | |
:database => 'dbfile_example' | |
) | |
class CreateProducts < ActiveRecord::Migration | |
def change | |
create_table :products do |t| | |
t.belongs_to :vendor, index: true | |
t.string :name | |
t.integer :instock | |
end | |
end | |
end | |
class CreateVendors < ActiveRecord::Migration | |
def change | |
create_table :vendors do |t| | |
t.string :name | |
end | |
end | |
end | |
class CreateSales < ActiveRecord::Migration | |
def change | |
create_table :sales do |t| | |
t.belongs_to :employee, index: true | |
t.belongs_to :product, index: true | |
t.time :date | |
end | |
end | |
end | |
class CreateEmployee < ActiveRecord::Migration | |
def change | |
create_table :employees do |t| | |
t.string :name | |
end | |
end | |
end | |
class Product < ActiveRecord::Base | |
belongs_to :vendor | |
has_many :sales | |
end | |
class Vendor < ActiveRecord::Base | |
has_many :products | |
end | |
class Sale < ActiveRecord::Base | |
belongs_to :emplopyee | |
belongs_to :product | |
end | |
class Employee < ActiveRecord::Base | |
has_many :sales | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment