mongomodel 0.2.11 → 0.2.12
Sign up to get free protection for your applications and to get access to all the features.
@@ -41,7 +41,9 @@ module MongoModel
|
|
41
41
|
delegate :foreign_key, :inverse_of, :to => :definition
|
42
42
|
|
43
43
|
def find_target
|
44
|
-
scoped
|
44
|
+
scoped.each { |doc|
|
45
|
+
doc.send("#{inverse_of}=", instance) if doc.respond_to?("#{inverse_of}=")
|
46
|
+
} + new_documents
|
45
47
|
end
|
46
48
|
|
47
49
|
def build(*args, &block)
|
@@ -52,24 +54,14 @@ module MongoModel
|
|
52
54
|
|
53
55
|
def create(*args, &block)
|
54
56
|
scoped.create(*args) do |doc|
|
55
|
-
|
56
|
-
doc.send("#{inverse_of}=", instance)
|
57
|
-
else
|
58
|
-
doc[foreign_key] = instance.id
|
59
|
-
end
|
60
|
-
|
57
|
+
set_inverse_association(doc)
|
61
58
|
block.call(doc) if block
|
62
59
|
end
|
63
60
|
end
|
64
61
|
|
65
62
|
def create!(*args, &block)
|
66
63
|
scoped.create!(*args) do |doc|
|
67
|
-
|
68
|
-
doc.send("#{inverse_of}=", instance)
|
69
|
-
else
|
70
|
-
doc[foreign_key] = instance.id
|
71
|
-
end
|
72
|
-
|
64
|
+
set_inverse_association(doc)
|
73
65
|
block.call(doc) if block
|
74
66
|
end
|
75
67
|
end
|
@@ -81,12 +73,7 @@ module MongoModel
|
|
81
73
|
end
|
82
74
|
|
83
75
|
def assign(doc)
|
84
|
-
|
85
|
-
doc.send("#{inverse_of}=", instance)
|
86
|
-
else
|
87
|
-
doc[foreign_key] = instance.id
|
88
|
-
end
|
89
|
-
|
76
|
+
set_inverse_association(doc)
|
90
77
|
doc.save(false) unless doc.new_record?
|
91
78
|
end
|
92
79
|
|
@@ -109,6 +96,14 @@ module MongoModel
|
|
109
96
|
@new_documents ||= []
|
110
97
|
end
|
111
98
|
|
99
|
+
def set_inverse_association(doc)
|
100
|
+
if doc.respond_to?("#{inverse_of}=")
|
101
|
+
doc.send("#{inverse_of}=", instance)
|
102
|
+
else
|
103
|
+
doc[foreign_key] = instance.id
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
112
107
|
def ensure_class(array)
|
113
108
|
array.is_a?(Array) ? array.each { |i| super(i) } : super
|
114
109
|
end
|
data/lib/mongomodel/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongomodel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
9
|
+
- 12
|
10
|
+
version: 0.2.12
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Sam Pohlenz
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-27 00:00:00 +10:30
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
28
30
|
segments:
|
29
31
|
- 3
|
30
32
|
- 0
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ~>
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 1
|
43
46
|
segments:
|
44
47
|
- 3
|
45
48
|
- 0
|
@@ -55,6 +58,7 @@ dependencies:
|
|
55
58
|
requirements:
|
56
59
|
- - ~>
|
57
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 23
|
58
62
|
segments:
|
59
63
|
- 1
|
60
64
|
- 1
|
@@ -70,6 +74,7 @@ dependencies:
|
|
70
74
|
requirements:
|
71
75
|
- - ">="
|
72
76
|
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
73
78
|
segments:
|
74
79
|
- 1
|
75
80
|
- 0
|
@@ -85,6 +90,7 @@ dependencies:
|
|
85
90
|
requirements:
|
86
91
|
- - "="
|
87
92
|
- !ruby/object:Gem::Version
|
93
|
+
hash: 27
|
88
94
|
segments:
|
89
95
|
- 1
|
90
96
|
- 3
|
@@ -257,6 +263,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
263
|
requirements:
|
258
264
|
- - ">="
|
259
265
|
- !ruby/object:Gem::Version
|
266
|
+
hash: 3
|
260
267
|
segments:
|
261
268
|
- 0
|
262
269
|
version: "0"
|
@@ -265,6 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
272
|
requirements:
|
266
273
|
- - ">="
|
267
274
|
- !ruby/object:Gem::Version
|
275
|
+
hash: 23
|
268
276
|
segments:
|
269
277
|
- 1
|
270
278
|
- 3
|