Skip to content

Instantly share code, notes, and snippets.

@adamdahan
Last active March 16, 2016 14:25
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 adamdahan/de872ec594bbb6706a64 to your computer and use it in GitHub Desktop.
Save adamdahan/de872ec594bbb6706a64 to your computer and use it in GitHub Desktop.
# 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