Module: Mongoid::Relations::Conversions

Extended by:
Conversions
Included in:
Conversions
Defined in:
lib/mongoid/relations/conversions.rb

Overview

Contains utility methods for object id conversion.

Instance Method Summary collapse

Instance Method Details

#flag(object, metadata) ⇒ Object

Mark the provided object as unconvertable to bson or not, and always return the provided object.

Examples:

Flag the object.

Conversions.flag(, 15)

Parameters:

  • object (Object)

    The object to flag.

  • The (Metadata)

    relation metadata.

Returns:

  • (Object)

    The provided object.

Since:

  • 2.3.0



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mongoid/relations/conversions.rb', line 21

def flag(object, )
  inverse = .inverse_klass
  if inverse.using_object_ids? || object.is_a?(BSON::ObjectId)
    object
  else
    object.tap do |obj|
      if obj.is_a?(String)
        obj.unconvertable_to_bson = true
      end
    end
  end
end