Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Forked from anonymous/mongoissue.rb
Created August 10, 2010 03:11
Show Gist options
  • Save jacquescrocker/516592 to your computer and use it in GitHub Desktop.
Save jacquescrocker/516592 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'
a.books.build title: 'Rhetoric'
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