Skip to content

Instantly share code, notes, and snippets.

@rurounijones

rurounijones/Output

Created May 19, 2011
Embed
What would you like to do?
$ 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
You can’t perform that action at this time.