Skip to content

Instantly share code, notes, and snippets.

@danlo
Created August 6, 2018 17:31
Show Gist options
  • Save danlo/d85b15d7dd986ed19bf8890b8691652c to your computer and use it in GitHub Desktop.
Save danlo/d85b15d7dd986ed19bf8890b8691652c to your computer and use it in GitHub Desktop.
brain twister
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