Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created March 2, 2015 22:40
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 tenderlove/365383d651dbb8e73f07 to your computer and use it in GitHub Desktop.
Save tenderlove/365383d651dbb8e73f07 to your computer and use it in GitHub Desktop.
require 'active_record'
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
class Article < ActiveRecord::Base
has_one :comment
end
class Comment < ActiveRecord::Base
validates :amazing, presence: true
def amazing; ''; end
end
ActiveRecord::Base.connection.instance_eval do
create_table(:articles)
create_table(:comments) do |t|
t.references :article
end
end
a = Article.create!
a.build_comment
a.save!
a = Article.find a.id
p a => a.comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment