Skip to content

Instantly share code, notes, and snippets.

@rurounijones
Created May 19, 2011 00:48
Show Gist options
  • Save rurounijones/979931 to your computer and use it in GitHub Desktop.
Save rurounijones/979931 to your computer and use it in GitHub Desktop.
$ ruby test.rb
Parent (after_initialize):
Parent (Outside object): #<Template:0x7f91a16d3078>
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler'
Bundler.require(:default)
Mongoid.database = Mongo::Connection.new('localhost').db('mongoid_xml_test_2')
class Template
include Mongoid::Document
embeds_many :pages
end
class Page
include Mongoid::Document
embedded_in :template, :inverse_of => :pages
after_initialize :do_processing
def do_processing
# Returns nil
puts "Parent (after_initialize): #{self._parent}"
end
end
t = Template.new
p = t.pages.new
# Returns the parent
puts "Parent (Outside object): #{p._parent}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment