Created
December 6, 2010 21:50
-
-
Save adamzaninovich/731032 to your computer and use it in GitHub Desktop.
Using Mongoid without Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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