Last active
March 16, 2016 14:25
-
-
Save adamdahan/de872ec594bbb6706a64 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 any necessary gems | |
require 'active_record' | |
require 'pry' | |
require 'sqlite3' | |
ActiveRecord::Base.establish_connection( | |
adapter: 'sqlite3', | |
database: ':memory:' | |
) | |
ActiveRecord::Schema.define do | |
create_table :shows, force: true do |t| | |
t.string :name | |
t.timestamps | |
end | |
create_table :episodes, force: true do |t| | |
t.string :name | |
t.belongs_to :show | |
t.timestamps | |
end | |
end | |
class Show < ActiveRecord::Base | |
validates :name | |
has_many :episodes | |
end | |
class Episode < ActiveRecord::Base | |
belongs_to :show, required: true | |
end | |
big_bang_theory = Show.create(name: "Big Bang") | |
seinfeld = Show.create(name: "seinfeld") | |
one_tree_hill = Show.create(name: "One Tree Hill") | |
big_bang_theory.episodes.create(name: "Fly to the moon") | |
big_bang_theory.episodes.create(name: "Jump higher") | |
big_bang_theory.episodes.create(name: "Ya mon") | |
binding.pry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment