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
# File 'lib/mongoid/relations/conversions.rb', line 21

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