Created
August 6, 2018 17:31
-
-
Save danlo/d85b15d7dd986ed19bf8890b8691652c to your computer and use it in GitHub Desktop.
brain twister
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
class BaseDoc | |
include Mongoid::Document | |
has_one :child, class_name: 'ChildDoc', inverse_of: :parent | |
field :data, type: String | |
end | |
class ChildDoc | |
include Mongoid::Document | |
belongs_to :parent, class_name: 'BaseDoc', inverse_of: :child, optional: true | |
field :data, type: String | |
end | |
base = BaseDoc.create(data: 'dog') | |
child = ChildDoc.create(data: 'cat') | |
child.parent = base | |
child.save | |
puts "GlobalID::Identification === base is #{GlobalID::Identification === base}" | |
puts "GlobalID::Identification === child is #{GlobalID::Identification === child}" | |
base2 = ChildDoc.where(data: 'cat').first.parent | |
puts "GlobalID::Identification === base2 is #{GlobalID::Identification === base2}" | |
puts "base2.is_a?(GlobalID::Identification) is #{base2.is_a?(GlobalID::Identification)}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment