Skip to content

Instantly share code, notes, and snippets.

@ricn
Created April 11, 2011 21:26
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 ricn/914389 to your computer and use it in GitHub Desktop.
Save ricn/914389 to your computer and use it in GitHub Desktop.
require "rubygems"
require "mongoid"
Mongoid.configure do |config|
name = "mongoid_bug"
host = "localhost"
config.master = Mongo::Connection.new.db(name)
config.persist_in_safe_mode = false
end
class Page
include Mongoid::Document
after_update :write_update_activity
identity :type => String
field :title, :type => String
referenced_in :account
protected
def write_update_activity
puts "update callback"
end
end
class Account
include Mongoid::Document
identity :type => String
field :subdomain, :type => String
index :subdomain, :unique => true
references_many :pages, :dependent => :destroy, :index => true, :autosave => true
end
account = Account.find_or_create_by(:subdomain => "mongoid")
page = Page.new(:title => "Mongoid")
account.pages << page
page.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment