mongoid_max_denormalize 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,7 +22,7 @@ module Mongoid
|
|
22
22
|
klass.field "#{relation}_count", type: Integer, default: 0
|
23
23
|
end
|
24
24
|
|
25
|
-
|
25
|
+
klass.class_eval <<-EOM, __FILE__, __LINE__
|
26
26
|
before_create :denormalize_from_#{relation}
|
27
27
|
|
28
28
|
def denormalize_from_#{relation}(force=false)
|
@@ -53,14 +53,17 @@ module Mongoid
|
|
53
53
|
|
54
54
|
nil
|
55
55
|
end
|
56
|
-
EOM
|
57
|
-
klass.class_eval callback_code
|
56
|
+
EOM
|
58
57
|
|
59
|
-
|
58
|
+
meta.klass.class_eval <<-EOM, __FILE__, __LINE__
|
60
59
|
around_save :denormalize_to_#{inverse_relation}
|
61
60
|
|
62
61
|
def denormalize_to_#{inverse_relation}
|
63
|
-
|
62
|
+
if !changed? && !new_record?
|
63
|
+
yield if block_given?
|
64
|
+
return
|
65
|
+
end
|
66
|
+
|
64
67
|
was_new = new_record?
|
65
68
|
was_added = false
|
66
69
|
was_removed = false
|
@@ -219,8 +222,7 @@ EOM
|
|
219
222
|
to_update.reject! {|k,v| v.empty?}
|
220
223
|
#{klass}.collection.find(:_id => remote_id).update_all(to_update) unless to_update.empty?
|
221
224
|
end
|
222
|
-
EOM
|
223
|
-
meta.klass.class_eval callback_code
|
225
|
+
EOM
|
224
226
|
end
|
225
227
|
|
226
228
|
def allowed_options
|
@@ -11,11 +11,11 @@ module Mongoid
|
|
11
11
|
klass.field "#{relation}_#{field}", type: field_meta.try(:type)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
14
|
+
klass.class_eval <<-EOM, __FILE__, __LINE__
|
15
15
|
before_save :denormalize_from_#{relation}
|
16
16
|
|
17
17
|
def denormalize_from_#{relation}
|
18
|
-
return unless #{meta.key}_changed?
|
18
|
+
return true unless #{meta.key}_changed?
|
19
19
|
|
20
20
|
fields = [#{Base.array_code_for(fields)}]
|
21
21
|
if #{meta.key}.nil?
|
@@ -30,14 +30,16 @@ module Mongoid
|
|
30
30
|
|
31
31
|
true
|
32
32
|
end
|
33
|
-
EOM
|
34
|
-
klass.class_eval callback_code
|
33
|
+
EOM
|
35
34
|
|
36
|
-
|
35
|
+
meta.klass.class_eval <<-EOM, __FILE__, __LINE__
|
37
36
|
around_save :denormalize_to_#{inverse_relation}
|
38
37
|
|
39
38
|
def denormalize_to_#{inverse_relation}(force = false)
|
40
|
-
|
39
|
+
unless changed? || force
|
40
|
+
yield if block_given?
|
41
|
+
return
|
42
|
+
end
|
41
43
|
|
42
44
|
fields = [#{Base.array_code_for(fields)}]
|
43
45
|
fields_only = [#{Base.array_code_for(fields_only)}]
|
@@ -76,10 +78,9 @@ EOM
|
|
76
78
|
to_set[:"#{relation}_\#{field}"] = nil
|
77
79
|
end
|
78
80
|
|
79
|
-
#{inverse_relation}.update to_set
|
81
|
+
#{inverse_relation}.update(to_set) unless to_set.empty?
|
80
82
|
end
|
81
|
-
EOM
|
82
|
-
meta.klass.class_eval callback_code
|
83
|
+
EOM
|
83
84
|
end
|
84
85
|
|
85
86
|
end
|