para 0.8.3.1 → 0.8.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/para/attribute_field/relation.rb +14 -3
- data/lib/para/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 263a0c4e059b700b6557076837f0e9dc6c0e577538ae4b864a1699a9bb06ce2e
|
4
|
+
data.tar.gz: ef5ad53a24de69abce3a43c7b55c6fbf6f12f32e0e52bb4ae152a2f63ba553f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f2a8ec0abb35f9c78e6cd6b555e8c0403e43e669f1e48326c80f015129327b6da064a5a7efcac0f2127db08b28b72fec0210258038be33e104bfc26cb32a650
|
7
|
+
data.tar.gz: 4d066ed1cf92b3cfa029d66ce73f047ff1670925e45ab66b0543db741330cfea546fe739d9adec0aa08f85a12c473b825df2c11631729951f13c05acde063cc6
|
@@ -43,8 +43,12 @@ module Para
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Takes an array of ids and a block. Check for each id if model exists
|
46
|
-
# and create one if not.
|
47
|
-
#
|
46
|
+
# and create one if not.
|
47
|
+
#
|
48
|
+
# Example : [12, "foo"] will try to create a model with
|
49
|
+
# 'foo' as a name, title or any other attribute referenced in
|
50
|
+
# the `Para.config.resource_name_methods` configuration param.
|
51
|
+
#
|
48
52
|
def on_the_fly_creation ids, &block
|
49
53
|
Array.wrap(ids).each do |id|
|
50
54
|
if !reflection.klass.exists?(id: id)
|
@@ -56,7 +60,14 @@ module Para
|
|
56
60
|
if resource.respond_to?(setter_name)
|
57
61
|
resource.send(setter_name, id)
|
58
62
|
|
59
|
-
|
63
|
+
# This check avoids multiple creation of the same resource with
|
64
|
+
# a given attribute value and ensure all resources from the form
|
65
|
+
# that reference that new resource name are associated to the
|
66
|
+
# same parent resource.
|
67
|
+
if (existing_resource = reflection.klass.find_by(method_name => id))
|
68
|
+
block.call(existing_resource, id)
|
69
|
+
break
|
70
|
+
elsif resource.save
|
60
71
|
block.call(resource, id)
|
61
72
|
break
|
62
73
|
end
|
data/lib/para/version.rb
CHANGED