Module: Mongoid::History::Trackable::RelationMethods

Defined in:
lib/mongoid/history/trackable.rb

Instance Method Summary collapse

Instance Method Details

#embeds_many?(field) ⇒ Boolean

Indicates whether there is an Embedded::Many relation for the given embedded field.

Parameters:

  • field (String | Symbol)

    The name of the embedded field.

Returns:

  • (Boolean)

    true if there is an Embedded::Many relation for the given embedded field.



384
385
386
387
388
389
390
# File 'lib/mongoid/history/trackable.rb', line 384

def embeds_many?(field)
  relation_of(field) == if Mongoid::Compatibility::Version.mongoid7_or_newer?
                          Mongoid::Association::Embedded::EmbedsMany::Proxy
                        else
                          Mongoid::Relations::Embedded::Many
                        end
end

#embeds_one?(field) ⇒ Boolean

Indicates whether there is an Embedded::One relation for the given embedded field.

Parameters:

  • embed (String | Symbol)

    The name of the embedded field.

Returns:

  • (Boolean)

    true if there is an Embedded::One relation for the given embedded field.



371
372
373
374
375
376
377
# File 'lib/mongoid/history/trackable.rb', line 371

def embeds_one?(field)
  relation_of(field) == if Mongoid::Compatibility::Version.mongoid7_or_newer?
                          Mongoid::Association::Embedded::EmbedsOne::Proxy
                        else
                          Mongoid::Relations::Embedded::One
                        end
end

#relation_alias(embed) ⇒ String

Retrieves the database representation of an embedded field name, in case the :store_as option is used.

Parameters:

  • embed (String | Symbol)

    The name or alias of the embedded field.

Returns:

  • (String)

    The database name of the embedded field.



397
398
399
# File 'lib/mongoid/history/trackable.rb', line 397

def relation_alias(embed)
  relation_aliases[embed]
end

#relation_class_of(field) ⇒ nil | Constant

Returns a relation class for the given field.

Parameters:

  • field (String | Symbol)

    The name of the field.

Returns:

  • (nil | Constant)

    Class being related.



361
362
363
364
# File 'lib/mongoid/history/trackable.rb', line 361

def relation_class_of(field)
  meta = meta_of(field)
  return meta.class_name.constantize if meta
end