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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57109a780f37db890a9b4fb0a567ff449d0d0e9c73c0ede097f3636f868c7ba8
4
- data.tar.gz: 45d5e7ec1dac97d9e49b7871eb7c84c5d6bf93e81c57f861e84492511b3bf6f9
3
+ metadata.gz: 263a0c4e059b700b6557076837f0e9dc6c0e577538ae4b864a1699a9bb06ce2e
4
+ data.tar.gz: ef5ad53a24de69abce3a43c7b55c6fbf6f12f32e0e52bb4ae152a2f63ba553f4
5
5
  SHA512:
6
- metadata.gz: 5a230c4d409cb6340cdc5156b79a9dbfe3883f040a6f2f3b20d8bc86d266b7a788dcd8a975e691c6923f2843ca55c5bc2959baa5d572df0611a77a7739879a7f
7
- data.tar.gz: 85cf71a9c7499b47f85a4b6eefa2facab6acb0a9894d5b6888f9b28a7a443361a303d56fbfaf57748b0ca105ca4ca3447389f545f02b2eacb79bf987ba68f91a
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. E.g: [12, "foo"] will try to create a model with
47
- # 'foo'
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
- if resource.save
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
@@ -1,3 +1,3 @@
1
1
  module Para
2
- VERSION = '0.8.3.1'
2
+ VERSION = '0.8.3.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3.1
4
+ version: 0.8.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino