Skip to content

Instantly share code, notes, and snippets.

@FaisalAl-Tameemi
Last active February 16, 2016 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FaisalAl-Tameemi/0167a2209cf81a4cb7e8 to your computer and use it in GitHub Desktop.
Save FaisalAl-Tameemi/0167a2209cf81a4cb7e8 to your computer and use it in GitHub Desktop.
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
class Car < ActiveRecord::Base
belongs_to :make
end
gem 'activerecord'
gem 'pg'
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