neo4j 9.5.2 → 9.5.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0364211168add80fe38bd3274825f155430521e2f6fb2e7228dad3e49aa057ac'
4
- data.tar.gz: c12278922c2b982334a564b85bf572a6db59fbd9c8ed7b520823a267c6d82562
3
+ metadata.gz: 822965793898b0cdde8a1e6410520b411478b84e849ee4130a53e6391858f8c4
4
+ data.tar.gz: c92710ffdbca32f588378bf11ea0466fc69233f571656e499b0287fa685f1578
5
5
  SHA512:
6
- metadata.gz: e063079054524c0843e720158e0af61fbb2b9c4121d38fac4fd1eea3648b95af196f63d8c3585491d4518535f398dde6b733a55baa2f0798dc8bf7927cc821b2
7
- data.tar.gz: e7822e8abf2eb73bce2011bbbb016f60ace21bc93ddaf7e1db89f3e9a3c0614e49fbc89f14990bf2f9f63fddbe5a3a54371b7ef6769737eea85735d304c8d8c6
6
+ metadata.gz: ff8a3d6a6122ad2f9fee70dcafbb10a2c30de757c0d98b755547334d56b5df020ae66eebaa12750dbdb2ab418a57ee071fd736960225426e0d55bef178e104bf
7
+ data.tar.gz: 19a8e93b5dd488c8d119d48230a02127b2622842de1adda468fe57f996ad00ec128f927e2b05e5ddea2cf4fd298cde324a5c7f3c90a16473614ea48ca838563f
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
3
3
  This file should follow the standards specified on [http://keepachangelog.com/]
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [9.5.3] 2019-08-16
7
+
8
+ ## Fixed
9
+
10
+ - Enforces has_one uniqness constraint on relationship with config flag. (#1566)
11
+ - Restricting activemodel and activesupport version to < 6.0.
12
+
6
13
  ## [9.5.2] 2019-08-06
7
14
 
8
15
  ## Fixed
@@ -33,3 +33,6 @@ cache_class_names: true
33
33
  # class_name_property: :_classname
34
34
 
35
35
  transform_rel_type: :upcase
36
+
37
+ # Enforce has_one relationship. When same reationship is created on reverse object with another object, raise the error.
38
+ enforce_has_one: false
@@ -3,7 +3,7 @@ module Neo4j::ActiveNode
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  class NonPersistedNodeError < Neo4j::Error; end
6
-
6
+ class HasOneConstraintError < Neo4j::Error; end
7
7
  # Return this object from associations
8
8
  # It uses a QueryProxy to get results
9
9
  # But also caches results and can have results cached on it
@@ -229,14 +229,27 @@ module Neo4j::ActiveNode
229
229
  end
230
230
  end
231
231
 
232
- def delete_has_one_rel(active_rel, direction, target_class)
233
- rel = active_rel_corresponding_rel(active_rel, direction, target_class)
234
- delete_rel(rel.last) if rel && rel.last.type == :has_one
232
+ def validate_reverse_has_one_core_rel(association, other_node)
233
+ return unless Neo4j::Config[:enforce_has_one]
234
+ reverse_assoc = reverse_association(association)
235
+ validate_has_one_rel!(reverse_assoc, other_node) if reverse_assoc && reverse_assoc.type == :has_one
236
+ end
237
+
238
+ def reverse_association(association)
239
+ reverse_assoc = self.class.associations.find do |_key, assoc|
240
+ association.inverse_of?(assoc) || assoc.inverse_of?(association)
241
+ end
242
+ reverse_assoc && reverse_assoc.last
243
+ end
244
+
245
+ def validate_reverse_has_one_active_rel(active_rel, direction, other_node)
246
+ rel = active_rel_corresponding_rel(active_rel, direction, other_node.class)
247
+ validate_has_one_rel!(rel.last, other_node) if rel && rel.last.type == :has_one
235
248
  end
236
249
 
237
- def delete_rel(rel)
238
- send("#{rel.name}=", nil)
239
- association_proxy_cache.clear
250
+ def validate_has_one_rel!(rel, other_node)
251
+ raise_error = (node = send(rel.name.to_s)) && node != other_node
252
+ fail(HasOneConstraintError, "node #{self.class}##{neo_id} has a has_one relationship with #{other_node.class}##{other_node.neo_id}") if raise_error
240
253
  end
241
254
 
242
255
  def active_rel_corresponding_rel(active_rel, direction, target_class)
@@ -208,7 +208,7 @@ module Neo4j
208
208
  Neo4j::ActiveBase.run_transaction do
209
209
  other_nodes.each do |other_node|
210
210
  if other_node.neo_id
211
- other_node.try(:delete_reverse_relationship, association)
211
+ other_node.try(:validate_reverse_has_one_core_rel, association, @start_object)
212
212
  else
213
213
  other_node.save
214
214
  end
@@ -7,17 +7,5 @@ module Neo4j::ActiveNode
7
7
  fail "Can't access relationship on a non persisted node" unless _persisted_obj
8
8
  _persisted_obj
9
9
  end
10
-
11
- def delete_reverse_relationship(association)
12
- reverse_assoc = reverse_association(association)
13
- delete_rel(reverse_assoc) if reverse_assoc && reverse_assoc.type == :has_one
14
- end
15
-
16
- def reverse_association(association)
17
- reverse_assoc = self.class.associations.find do |_key, assoc|
18
- association.inverse_of?(assoc) || assoc.inverse_of?(association)
19
- end
20
- reverse_assoc && reverse_assoc.last
21
- end
22
10
  end
23
11
  end
@@ -45,16 +45,17 @@ module Neo4j::ActiveRel
45
45
 
46
46
  def create_model
47
47
  validate_node_classes!
48
- delete_has_one_rel
48
+ validate_has_one_rel
49
49
  rel = _create_rel
50
50
  return self unless rel.respond_to?(:props)
51
51
  init_on_load(rel, from_node, to_node, @rel_type)
52
52
  true
53
53
  end
54
54
 
55
- def delete_has_one_rel
56
- to_node.delete_has_one_rel(self, :in, from_node.class) if to_node.persisted?
57
- from_node.delete_has_one_rel(self, :out, to_node.class) if from_node.persisted?
55
+ def validate_has_one_rel
56
+ return unless Neo4j::Config[:enforce_has_one]
57
+ to_node.validate_reverse_has_one_active_rel(self, :in, from_node) if to_node.persisted?
58
+ from_node.validate_reverse_has_one_active_rel(self, :out, to_node) if from_node.persisted?
58
59
  end
59
60
 
60
61
  def query_as(var)
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = '9.5.2'
2
+ VERSION = '9.5.3'
3
3
  end
@@ -33,8 +33,8 @@ DESCRIPTION
33
33
  'bug_tracker_uri' => 'https://github.com/neo4jrb/neo4j/issues'
34
34
  }
35
35
 
36
- s.add_dependency('activemodel', '>= 4.0')
37
- s.add_dependency('activesupport', '>= 4.0')
36
+ s.add_dependency('activemodel', ['>= 4.0', '< 6'])
37
+ s.add_dependency('activesupport', ['>= 4.0', '< 6'])
38
38
  s.add_dependency('i18n', '!= 1.3.0') # version 1.3.0 introduced a bug with `symbolize_key`
39
39
  s.add_dependency('neo4j-core', '>= 9.0.0')
40
40
  s.add_dependency('orm_adapter', '~> 0.5.0')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4j
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.5.2
4
+ version: 9.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Ronge, Brian Underwood, Chris Grigg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-06 00:00:00.000000000 Z
11
+ date: 2019-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: activesupport
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -31,6 +37,9 @@ dependencies:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
33
39
  version: '4.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6'
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +47,9 @@ dependencies:
38
47
  - - ">="
39
48
  - !ruby/object:Gem::Version
40
49
  version: '4.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6'
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: i18n
43
55
  requirement: !ruby/object:Gem::Requirement