1
1
# frozen_string_literal: true
2
- # rubocop:todo all
3
2
4
3
module Mongoid
5
4
module Association
6
-
7
5
# This module contains the core macros for defining associations between
8
6
# documents. They can be either embedded or referenced.
9
7
module Macros
@@ -36,7 +34,7 @@ module Macros
36
34
# @api private
37
35
class_attribute :aliased_associations
38
36
39
- # @return [ Set<String> ] The set of associations that are configured
37
+ # @return [ Set<String> ] The set of associations that are configured
40
38
# with :store_as parameter.
41
39
class_attribute :stored_as_associations
42
40
@@ -54,11 +52,11 @@ module Macros
54
52
#
55
53
# @return [ Hash ] The associations.
56
54
def associations
57
- self . relations
55
+ relations
58
56
end
59
57
58
+ # Class methods for associations.
60
59
module ClassMethods
61
-
62
60
# Adds the association back to the parent document. This macro is
63
61
# necessary to set the references from the child back to the parent
64
62
# document. If a child does not define this association calling
@@ -151,6 +149,8 @@ def belongs_to(name, options = {}, &block)
151
149
define_association! ( __method__ , name , options , &block )
152
150
end
153
151
152
+ # rubocop:disable Naming/PredicateName
153
+
154
154
# Adds a referenced association from a parent Document to many
155
155
# Documents in another database or collection.
156
156
#
@@ -217,15 +217,17 @@ def has_one(name, options = {}, &block)
217
217
define_association! ( __method__ , name , options , &block )
218
218
end
219
219
220
+ # rubocop:enable Naming/PredicateName
221
+
220
222
private
221
223
222
224
def define_association! ( macro_name , name , options = { } , &block )
223
225
Association ::MACRO_MAPPING [ macro_name ] . new ( self , name , options , &block ) . tap do |assoc |
224
226
assoc . setup!
225
- self . relations = self . relations . merge ( name => assoc )
227
+ self . relations = relations . merge ( name => assoc )
226
228
if assoc . embedded? && assoc . respond_to? ( :store_as ) && assoc . store_as != name
227
- self . aliased_associations [ assoc . store_as ] = name
228
- self . stored_as_associations << assoc . store_as
229
+ aliased_associations [ assoc . store_as ] = name
230
+ stored_as_associations << assoc . store_as
229
231
end
230
232
end
231
233
end
0 commit comments