Last active
February 16, 2016 22:19
-
-
Save FaisalAl-Tameemi/0167a2209cf81a4cb7e8 to your computer and use it in GitHub Desktop.
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
require 'active_record' | |
require_relative('./make') | |
require_relative('./car') | |
class App | |
def run | |
ActiveRecord::Base.establish_connection( | |
adapter: :postgresql, | |
database: 'dealership' | |
) | |
bmw = Make.create(company_name: "BMW", established_at: 1916) | |
p bmw | |
three_series = Car.create(stock: 20, model: "3 Series", make: bmw) | |
four_series = Car.create(stock: 3, model: "4 Series", make: bmw) | |
five_series = Car.create(stock: 1, model: "M5", make_id: bmw.id) | |
# Car.where({make_id: bmw.id}) | |
bmw.cars.each do |current_car| | |
p current_car | |
end | |
# Make.find({id: five_series.make_id}) | |
p five_series.make | |
end | |
end | |
App.new.run |
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 Car < ActiveRecord::Base | |
belongs_to :make | |
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
gem 'activerecord' | |
gem 'pg' |
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 Make < ActiveRecord::Base | |
has_many :cars | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment