Class: ActiveScaffold::DataStructures::Association::Mongoid

Inherits:
Abstract
  • Object
show all
Defined in:
lib/active_scaffold/data_structures/association/mongoid.rb

Direct Known Subclasses

ActiveMongoid

Instance Attribute Summary

Attributes inherited from Abstract

#reverse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#allow_join?, #as, #collection?, #counter_cache, #counter_cache_hack?, #initialize, #inverse_for?, #klass, #primary_key, #readonly?, #respond_to_target?, #reverse_association, #scope, #singular?, #source_reflection, #through?, #through_collection?, #through_reflection, #through_singular?

Constructor Details

This class inherits a constructor from ActiveScaffold::DataStructures::Association::Abstract

Class Method Details

.reflect_on_all_associations(klass) ⇒ Object



47
48
49
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 47

def self.reflect_on_all_associations(klass)
  klass.relations.values
end

Instance Method Details

#association_primary_keyObject



27
28
29
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 27

def association_primary_key
  @association.primary_key
end

#belongs_to?Boolean

Returns:

  • (Boolean)


5
6
7
8
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 5

def belongs_to?
  # once Ruby 2.6 support is dropped, use macro_mapping? always
  defined?(::Mongoid::Association) ? macro_mapping?(:belongs_to) : super
end

#foreign_typeObject



31
32
33
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 31

def foreign_type
  @association.type
end

#habtm?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 18

def habtm?
  defined?(::Mongoid::Association) ? macro_mapping?(:has_and_belongs_to_many) : super
end

#has_many?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)


14
15
16
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 14

def has_many? # rubocop:disable Naming/PredicateName
  defined?(::Mongoid::Association) ? macro_mapping?(:has_many) : super
end

#has_one?Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)


10
11
12
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 10

def has_one? # rubocop:disable Naming/PredicateName
  defined?(::Mongoid::Association) ? macro_mapping?(:has_one) : super
end

#macro_mapping?(macro) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 51

def macro_mapping?(macro)
  @association.is_a? ::Mongoid::Association::MACRO_MAPPING[macro]
end

#polymorphic?Boolean

polymorphic belongs_to

Returns:

  • (Boolean)


23
24
25
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 23

def polymorphic?
  belongs_to? && @association.polymorphic?
end

#quoted_primary_keyObject



43
44
45
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 43

def quoted_primary_key
  '_id'
end

#quoted_table_nameObject



39
40
41
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 39

def quoted_table_name
  table_name
end

#table_nameObject



35
36
37
# File 'lib/active_scaffold/data_structures/association/mongoid.rb', line 35

def table_name
  @association.klass.collection.name
end