Skip to content

Instantly share code, notes, and snippets.

@ricn
Created Apr 11, 2011
Embed
What would you like to do?
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