Created
May 19, 2011 00:48
-
-
Save rurounijones/979931 to your computer and use it in GitHub Desktop.
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
$ ruby test.rb | |
Parent (after_initialize): | |
Parent (Outside object): #<Template:0x7f91a16d3078> |
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
#!/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