Skip to content

Instantly share code, notes, and snippets.

@adamzaninovich
Created December 6, 2010 21:50
Show Gist options
  • Save adamzaninovich/731032 to your computer and use it in GitHub Desktop.
Save adamzaninovich/731032 to your computer and use it in GitHub Desktop.
Using Mongoid without Rails
require 'mongoid'
Mongoid::Config.instance.from_hash({"database" => "oid"})
class Tweeter
include Mongoid::Document
field :user
embeds_many :tweets
end
class Tweet
include Mongoid::Document
field :status
embedded_in :tweeter, :inverse_of => :tweets
end
# just create user
user = Tweeter.new(:user => 'bill')
user.save
# create tweet and user
tweet = Tweet.new(:status => "This is a tweet!")
tweet.tweeter = Tweeter.new(:user => 'ted')
tweet.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment