Skip to content

Instantly share code, notes, and snippets.

Created August 10, 2010 03:09
Show Gist options
  • Save anonymous/516590 to your computer and use it in GitHub Desktop.
Save anonymous/516590 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'bundler'
Bundler.require
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('foo')
end
class Author
include Mongoid::Document
references_many :books,:inverse_of => :author
field :name
end
class Book
include Mongoid::Document
referenced_in :author
field :title
end
a = Author.new name: 'Aristotle'
b = Book.new title: 'Rhetoric'
b.author = a
b.save
a.save
puts a.books.first.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment