neo4j 5.2.15 → 6.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -19
- data/Gemfile +1 -1
- data/lib/neo4j.rb +4 -1
- data/lib/neo4j/active_node.rb +6 -15
- data/lib/neo4j/active_node/has_n.rb +52 -21
- data/lib/neo4j/active_node/has_n/association.rb +1 -1
- data/lib/neo4j/active_node/id_property.rb +1 -1
- data/lib/neo4j/active_node/id_property/accessor.rb +1 -1
- data/lib/neo4j/active_node/labels.rb +7 -101
- data/lib/neo4j/active_node/labels/index.rb +87 -0
- data/lib/neo4j/active_node/persistence.rb +3 -2
- data/lib/neo4j/active_node/query.rb +1 -1
- data/lib/neo4j/active_node/query/query_proxy.rb +7 -9
- data/lib/neo4j/active_node/query/query_proxy_eager_loading.rb +0 -1
- data/lib/neo4j/active_node/query/query_proxy_link.rb +12 -4
- data/lib/neo4j/active_node/query/query_proxy_methods.rb +4 -6
- data/lib/neo4j/active_node/query/query_proxy_unpersisted.rb +4 -8
- data/lib/neo4j/active_node/unpersisted.rb +12 -10
- data/lib/neo4j/active_node/validations.rb +2 -2
- data/lib/neo4j/active_rel.rb +7 -4
- data/lib/neo4j/active_rel/persistence.rb +13 -4
- data/lib/neo4j/active_rel/query.rb +8 -0
- data/lib/neo4j/active_rel/related_node.rb +1 -27
- data/lib/neo4j/errors.rb +2 -0
- data/lib/neo4j/schema/operation.rb +91 -0
- data/lib/neo4j/shared.rb +3 -3
- data/lib/neo4j/shared/callbacks.rb +2 -7
- data/lib/neo4j/shared/{declared_property_manager.rb → declared_properties.rb} +34 -2
- data/lib/neo4j/shared/declared_property.rb +19 -0
- data/lib/neo4j/shared/declared_property/index.rb +37 -0
- data/lib/neo4j/shared/initialize.rb +2 -2
- data/lib/neo4j/shared/persistence.rb +3 -25
- data/lib/neo4j/shared/property.rb +24 -10
- data/lib/neo4j/shared/type_converters.rb +131 -6
- data/lib/neo4j/tasks/migration.rake +3 -3
- data/lib/neo4j/type_converters.rb +1 -1
- data/lib/neo4j/version.rb +1 -1
- data/neo4j.gemspec +2 -2
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb4da367af9c6c6253c1d7f744ea39807a8c15b7
|
4
|
+
data.tar.gz: 17b6b00c6b522b83aa27ca9ba1780542a15ae8bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97d79f821bf11cb74a5b53a964a5796c74a266775a2cebc6669bfa104f727dddf654fca104cc2c1dcd3cf9eb6f6e2babb8f0a625144bf360383f5343f6f6c76f
|
7
|
+
data.tar.gz: f2c614f9b21c87942f0f50ae0bf0131edc3a6a41023d551594d1cb8e0cf7f7dca7480d2ca8fdd4e6da9f4a1333b9e376a547572b87ae9d4e8e81736dd8e1a769
|
data/CHANGELOG.md
CHANGED
@@ -3,32 +3,30 @@ 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
|
-
## [
|
6
|
+
## [6.0.0.alpha.1] - 10-12-2015
|
7
7
|
|
8
|
-
###
|
9
|
-
|
10
|
-
- `#with_associations` should use multiple `OPTIONAL MATCH` clauses instead of one so that matches are independent (behavior changed in Neo4j 2.3.0)
|
11
|
-
|
12
|
-
## [5.2.13] - 10-26-2015
|
13
|
-
|
14
|
-
### Fixed
|
15
|
-
- Fixed `#after_initialize` and `#after_find` callbacks.
|
16
|
-
- The `#touch` method should to raise errors when unsuccessful and avoid `#attributes` for performance.
|
8
|
+
### Changed
|
17
9
|
|
18
|
-
|
10
|
+
- Refactoring around indexing and constraints in `Neo4j::ActiveNode`. The public interfaces are unchanged.
|
11
|
+
- `Neo4j::Shared::DeclaredPropertyManager` was renamed `Neo4j::Shared::DeclaredProperties`. All methods referencing the old name were updated to reflect this.
|
12
|
+
- Methods that were using `Neo4j::Session#on_session_available` were updated to reflect the upstream change to `on_next_session_available`.
|
13
|
+
- `rel_where` will now use ActiveRel classes for type conversion, when possible.
|
14
|
+
- Converters will look for a `converted?` method to determine whether an object is of the appropriate type for the database. This allows converters to be responsible for multiple types, if required.
|
15
|
+
- Removed the ability to set both an exact index and unique constraint on the same property in a model. Unique constraints also provide exact indexes.
|
16
|
+
- Deprecated all methods in ActiveRel's Query module except for those that allow finding by id.
|
17
|
+
- Return `true` on successful `#save!` calls (Thanks to jmdeldin)
|
19
18
|
|
20
|
-
###
|
21
|
-
- Fix the `#touch` method for `ActiveNode` and `ActiveRel`
|
19
|
+
### Added
|
22
20
|
|
23
|
-
|
21
|
+
- New classes for schema operations, predictably called `Neo4j::Schema::Operation` and subclasses `UniqueConstraintOperation` and `ExactIndexOperation`. These provide methods to aid in the additional, removal, and presence checking of indexes and constraints.
|
22
|
+
- A few methods were added to `Neo4j::Shared::DeclaredProperties` to make it easier to work with. In particular, `[key]` acts as a shortcut for `DeclaredProperties#registered_properties`.
|
23
|
+
- Type Converters were added for String, Integer, Fixnum, BigDecimal, and Boolean to provide type conversion for these objects in QueryProxy.
|
24
|
+
- Support for Array arguments to ActiveRel's `from_class` and `to_class`.
|
24
25
|
|
25
26
|
### Fixed
|
26
|
-
- Unable to give additional options as first argument to chained QueryProxy method
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
### Fixed
|
31
|
-
- `has_one` does not define `_id` methods if they are already defined. Also use `method_defined?` instead of `respond_to?` since it is at the class level
|
28
|
+
- Certain actions that were intended as once-in-the-app's-lifetime events, notably schema operations, will only occur immediately upon the first session's establishment.
|
29
|
+
- Context now set for Model.all QueryProxy so that logs can reflect that it wasn't just a raw Cypher query
|
32
30
|
|
33
31
|
## [5.2.9] - 09-30-2015
|
34
32
|
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'http://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
|
5
|
+
gem 'neo4j-core', github: 'neo4jrb/neo4j-core', branch: 'master'
|
6
6
|
# gem 'neo4j-core', path: '../neo4j-core'
|
7
7
|
|
8
8
|
# gem 'active_attr', github: 'neo4jrb/active_attr', branch: 'performance'
|
data/lib/neo4j.rb
CHANGED
@@ -25,12 +25,14 @@ require 'neo4j/shared/type_converters'
|
|
25
25
|
require 'neo4j/shared/rel_type_converters'
|
26
26
|
require 'neo4j/type_converters'
|
27
27
|
require 'neo4j/paginated'
|
28
|
+
require 'neo4j/schema/operation'
|
28
29
|
|
29
30
|
require 'neo4j/timestamps'
|
30
31
|
|
31
32
|
require 'neo4j/shared/callbacks'
|
33
|
+
require 'neo4j/shared/declared_property/index'
|
32
34
|
require 'neo4j/shared/declared_property'
|
33
|
-
require 'neo4j/shared/
|
35
|
+
require 'neo4j/shared/declared_properties'
|
34
36
|
require 'neo4j/shared/property'
|
35
37
|
require 'neo4j/shared/persistence'
|
36
38
|
require 'neo4j/shared/validations'
|
@@ -60,6 +62,7 @@ require 'neo4j/active_node/query/query_proxy_enumerable'
|
|
60
62
|
require 'neo4j/active_node/query/query_proxy_find_in_batches'
|
61
63
|
require 'neo4j/active_node/query/query_proxy_eager_loading'
|
62
64
|
require 'neo4j/active_node/query/query_proxy_link'
|
65
|
+
require 'neo4j/active_node/labels/index'
|
63
66
|
require 'neo4j/active_node/labels/reloading'
|
64
67
|
require 'neo4j/active_node/labels'
|
65
68
|
require 'neo4j/active_node/id_property/accessor'
|
data/lib/neo4j/active_node.rb
CHANGED
@@ -59,25 +59,16 @@ module Neo4j
|
|
59
59
|
|
60
60
|
def self.inherited(other)
|
61
61
|
inherit_id_property(other)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
Neo4j::ActiveNode::Labels.add_wrapped_class(other)
|
62
|
+
attributes.each_pair do |k, v|
|
63
|
+
other.inherit_property k.to_sym, v.clone, declared_properties[k].options
|
64
|
+
end
|
66
65
|
|
66
|
+
Neo4j::ActiveNode::Labels.add_wrapped_class(other)
|
67
67
|
super
|
68
68
|
end
|
69
69
|
|
70
|
-
def self.inherited_indexes(other)
|
71
|
-
return if indexed_properties.nil?
|
72
|
-
self.indexed_properties.each { |property| other.index property }
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.inherit_serialized_properties(other)
|
76
|
-
other.serialized_properties = self.serialized_properties
|
77
|
-
end
|
78
|
-
|
79
70
|
def self.inherit_id_property(other)
|
80
|
-
Neo4j::Session.
|
71
|
+
Neo4j::Session.on_next_session_available do |_|
|
81
72
|
next if other.manual_id_property? || !self.id_property?
|
82
73
|
id_prop = self.id_property_info
|
83
74
|
conf = id_prop[:type].empty? ? {auto: :uuid} : id_prop[:type]
|
@@ -85,7 +76,7 @@ module Neo4j
|
|
85
76
|
end
|
86
77
|
end
|
87
78
|
|
88
|
-
Neo4j::Session.
|
79
|
+
Neo4j::Session.on_next_session_available do |_|
|
89
80
|
next if manual_id_property?
|
90
81
|
id_property :uuid, auto: :uuid unless self.id_property?
|
91
82
|
|
@@ -22,7 +22,7 @@ module Neo4j::ActiveNode
|
|
22
22
|
# Default
|
23
23
|
def inspect
|
24
24
|
if @cached_result
|
25
|
-
|
25
|
+
result_nodes.inspect
|
26
26
|
else
|
27
27
|
"#<AssociationProxy @query_proxy=#{@query_proxy.inspect}>"
|
28
28
|
end
|
@@ -36,7 +36,15 @@ module Neo4j::ActiveNode
|
|
36
36
|
include Enumerable
|
37
37
|
|
38
38
|
def each(&block)
|
39
|
-
|
39
|
+
result_nodes.each(&block)
|
40
|
+
end
|
41
|
+
|
42
|
+
def ==(other)
|
43
|
+
self.to_a == other.to_a
|
44
|
+
end
|
45
|
+
|
46
|
+
def +(other)
|
47
|
+
self.to_a + other
|
40
48
|
end
|
41
49
|
|
42
50
|
def result
|
@@ -47,11 +55,30 @@ module Neo4j::ActiveNode
|
|
47
55
|
@cached_result
|
48
56
|
end
|
49
57
|
|
58
|
+
def result_nodes
|
59
|
+
return result if !@query_proxy.model
|
60
|
+
|
61
|
+
@cached_result = result.map do |object|
|
62
|
+
object.is_a?(Neo4j::ActiveNode) ? object : @query_proxy.model.find(object)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def result_ids
|
67
|
+
result.map do |object|
|
68
|
+
object.is_a?(Neo4j::ActiveNode) ? object.id : object
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
50
72
|
def cache_result(result)
|
51
73
|
@cached_result = result
|
52
74
|
@enumerable = (@cached_result || @query_proxy)
|
53
75
|
end
|
54
76
|
|
77
|
+
def add_to_cache(object)
|
78
|
+
@cached_result ||= []
|
79
|
+
@cached_result << object
|
80
|
+
end
|
81
|
+
|
55
82
|
def cache_query_proxy_result
|
56
83
|
@query_proxy.to_a.tap do |result|
|
57
84
|
cache_result(result)
|
@@ -74,7 +101,7 @@ module Neo4j::ActiveNode
|
|
74
101
|
super if target.nil?
|
75
102
|
|
76
103
|
cache_query_proxy_result if !cached? && !target.is_a?(Neo4j::ActiveNode::Query::QueryProxy)
|
77
|
-
clear_cache_result if target.is_a?(Neo4j::ActiveNode::Query::QueryProxy)
|
104
|
+
clear_cache_result if !QUERY_PROXY_METHODS.include?(method_name) && target.is_a?(Neo4j::ActiveNode::Query::QueryProxy)
|
78
105
|
|
79
106
|
target.public_send(method_name, *args, &block)
|
80
107
|
end
|
@@ -123,9 +150,13 @@ module Neo4j::ActiveNode
|
|
123
150
|
self.class.send(:association_query_proxy, name, {start_object: self}.merge!(options))
|
124
151
|
end
|
125
152
|
|
153
|
+
def association_proxy_hash(name, options = {})
|
154
|
+
[name.to_sym, options.values_at(:node, :rel, :labels, :rel_length)].hash
|
155
|
+
end
|
156
|
+
|
126
157
|
def association_proxy(name, options = {})
|
127
158
|
name = name.to_sym
|
128
|
-
hash =
|
159
|
+
hash = association_proxy_hash(name, options)
|
129
160
|
association_proxy_cache_fetch(hash) do
|
130
161
|
if result_cache = self.instance_variable_get('@source_query_proxy_result_cache')
|
131
162
|
result_by_previous_id = previous_proxy_results_by_previous_id(result_cache, name)
|
@@ -301,7 +332,10 @@ module Neo4j::ActiveNode
|
|
301
332
|
define_method(name) do |node = nil, rel = nil, options = {}|
|
302
333
|
# return [].freeze unless self._persisted_obj
|
303
334
|
|
304
|
-
|
335
|
+
if node.is_a?(Hash)
|
336
|
+
options = node
|
337
|
+
node = nil
|
338
|
+
end
|
305
339
|
|
306
340
|
association_proxy(name, {node: node, rel: rel, source_object: self, labels: options[:labels]}.merge!(options))
|
307
341
|
end
|
@@ -311,8 +345,6 @@ module Neo4j::ActiveNode
|
|
311
345
|
define_has_many_id_methods(name)
|
312
346
|
|
313
347
|
define_class_method(name) do |node = nil, rel = nil, options = {}|
|
314
|
-
options, node = node, nil if node.is_a?(Hash)
|
315
|
-
|
316
348
|
association_proxy(name, {node: node, rel: rel, labels: options[:labels]}.merge!(options))
|
317
349
|
end
|
318
350
|
end
|
@@ -327,7 +359,7 @@ module Neo4j::ActiveNode
|
|
327
359
|
|
328
360
|
def define_has_many_id_methods(name)
|
329
361
|
define_method_unless_defined("#{name.to_s.singularize}_ids") do
|
330
|
-
association_proxy(name).
|
362
|
+
association_proxy(name).result_ids
|
331
363
|
end
|
332
364
|
|
333
365
|
define_method_unless_defined("#{name.to_s.singularize}_ids=") do |ids|
|
@@ -340,7 +372,7 @@ module Neo4j::ActiveNode
|
|
340
372
|
end
|
341
373
|
|
342
374
|
def define_method_unless_defined(method_name, &block)
|
343
|
-
define_method(method_name, block) unless
|
375
|
+
define_method(method_name, block) unless respond_to?(method_name)
|
344
376
|
end
|
345
377
|
|
346
378
|
def define_has_one_methods(name)
|
@@ -351,38 +383,37 @@ module Neo4j::ActiveNode
|
|
351
383
|
define_has_one_id_methods(name)
|
352
384
|
|
353
385
|
define_class_method(name) do |node = nil, rel = nil, options = {}|
|
354
|
-
options, node = node, nil if node.is_a?(Hash)
|
355
|
-
|
356
386
|
association_proxy(name, {node: node, rel: rel, labels: options[:labels]}.merge!(options))
|
357
387
|
end
|
358
388
|
end
|
359
389
|
|
360
390
|
def define_has_one_id_methods(name)
|
361
|
-
|
362
|
-
association_proxy(name).
|
391
|
+
define_method("#{name}_id") do
|
392
|
+
association_proxy(name).result_ids.first
|
363
393
|
end
|
364
394
|
|
365
395
|
define_method_unless_defined("#{name}_id=") do |id|
|
366
396
|
association_proxy(name).replace_with(id)
|
367
397
|
end
|
368
398
|
|
369
|
-
|
399
|
+
define_method("#{name}_neo_id") do
|
370
400
|
association_proxy(name).pluck(:neo_id).first
|
371
401
|
end
|
372
402
|
end
|
373
403
|
|
374
404
|
def define_has_one_getter(name)
|
375
405
|
define_method(name) do |node = nil, rel = nil, options = {}|
|
376
|
-
|
377
|
-
|
378
|
-
|
406
|
+
if node.is_a?(Hash)
|
407
|
+
options = node
|
408
|
+
node = nil
|
409
|
+
end
|
379
410
|
|
380
411
|
# Return all results if a variable-length relationship length was given
|
381
|
-
|
412
|
+
association_proxy = association_proxy(name, {node: node, rel: rel}.merge!(options))
|
382
413
|
if options[:rel_length] && !options[:rel_length].is_a?(Fixnum)
|
383
|
-
|
414
|
+
association_proxy
|
384
415
|
else
|
385
|
-
|
416
|
+
association_proxy.result_nodes.first
|
386
417
|
end
|
387
418
|
end
|
388
419
|
end
|
@@ -395,7 +426,7 @@ module Neo4j::ActiveNode
|
|
395
426
|
Neo4j::Transaction.run { association_proxy(name).replace_with(other_node) }
|
396
427
|
# handle_non_persisted_node(other_node)
|
397
428
|
else
|
398
|
-
association_proxy(name).defer_create(other_node
|
429
|
+
association_proxy(name).defer_create(other_node)
|
399
430
|
end
|
400
431
|
end
|
401
432
|
end
|
@@ -179,7 +179,7 @@ module Neo4j
|
|
179
179
|
|
180
180
|
def apply_vars_from_options(options)
|
181
181
|
@relationship_class_name = options[:rel_class] && options[:rel_class].to_s
|
182
|
-
@relationship_type
|
182
|
+
@relationship_type = options[:type] && options[:type].to_sym
|
183
183
|
|
184
184
|
@model_class = options[:model_class]
|
185
185
|
@callbacks = {before: options[:before], after: options[:after]}
|
@@ -140,7 +140,7 @@ module Neo4j::ActiveNode
|
|
140
140
|
|
141
141
|
def id_property(name, conf = {})
|
142
142
|
self.manual_id_property = true
|
143
|
-
Neo4j::Session.
|
143
|
+
Neo4j::Session.on_next_session_available do |_|
|
144
144
|
@id_property_info = {name: name, type: conf}
|
145
145
|
TypeMethods.define_id_methods(self, name, conf)
|
146
146
|
constraint(name, type: :unique) unless conf[:constraint] == false
|
@@ -28,7 +28,7 @@ module Neo4j::ActiveNode::IdProperty
|
|
28
28
|
@default_property_key ||= default_properties_keys.first
|
29
29
|
end
|
30
30
|
|
31
|
-
# TODO: Move this to the
|
31
|
+
# TODO: Move this to the DeclaredProperties
|
32
32
|
def default_property(name, &block)
|
33
33
|
reset_default_properties(name) if default_properties.respond_to?(:size)
|
34
34
|
default_properties[name] = block
|
@@ -3,6 +3,7 @@ module Neo4j
|
|
3
3
|
# Provides a mapping between neo4j labels and Ruby classes
|
4
4
|
module Labels
|
5
5
|
extend ActiveSupport::Concern
|
6
|
+
include Neo4j::ActiveNode::Labels::Index
|
6
7
|
include Neo4j::ActiveNode::Labels::Reloading
|
7
8
|
|
8
9
|
WRAPPED_CLASSES = []
|
@@ -84,13 +85,13 @@ module Neo4j
|
|
84
85
|
def find(id)
|
85
86
|
map_id = proc { |object| object.respond_to?(:id) ? object.send(:id) : object }
|
86
87
|
|
87
|
-
result =
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
result = if id.is_a?(Array)
|
89
|
+
find_by_ids(id.map { |o| map_id.call(o) })
|
90
|
+
else
|
91
|
+
find_by_id(map_id.call(id))
|
92
|
+
end
|
92
93
|
fail Neo4j::RecordNotFound if result.blank?
|
93
|
-
result
|
94
|
+
result
|
94
95
|
end
|
95
96
|
|
96
97
|
# Finds the first record matching the specified conditions. There is no implied ordering so if order matters, you should specify it yourself.
|
@@ -116,71 +117,6 @@ module Neo4j
|
|
116
117
|
all.each(&:destroy)
|
117
118
|
end
|
118
119
|
|
119
|
-
# Creates a Neo4j index on given property
|
120
|
-
#
|
121
|
-
# This can also be done on the property directly, see Neo4j::ActiveNode::Property::ClassMethods#property.
|
122
|
-
#
|
123
|
-
# @param [Symbol] property the property we want a Neo4j index on
|
124
|
-
# @param [Hash] conf optional property configuration
|
125
|
-
#
|
126
|
-
# @example
|
127
|
-
# class Person
|
128
|
-
# include Neo4j::ActiveNode
|
129
|
-
# property :name
|
130
|
-
# index :name
|
131
|
-
# end
|
132
|
-
#
|
133
|
-
# @example with constraint
|
134
|
-
# class Person
|
135
|
-
# include Neo4j::ActiveNode
|
136
|
-
# property :name
|
137
|
-
#
|
138
|
-
# # below is same as: index :name, index: :exact, constraint: {type: :unique}
|
139
|
-
# index :name, constraint: {type: :unique}
|
140
|
-
# end
|
141
|
-
def index(property, conf = {})
|
142
|
-
Neo4j::Session.on_session_available do |_|
|
143
|
-
drop_constraint(property, type: :unique) if Neo4j::Label.constraint?(mapped_label_name, property)
|
144
|
-
_index(property, conf)
|
145
|
-
end
|
146
|
-
indexed_properties.push property unless indexed_properties.include? property
|
147
|
-
end
|
148
|
-
|
149
|
-
# Creates a neo4j constraint on this class for given property
|
150
|
-
#
|
151
|
-
# @example
|
152
|
-
# Person.constraint :name, type: :unique
|
153
|
-
#
|
154
|
-
def constraint(property, constraints)
|
155
|
-
Neo4j::Session.on_session_available do |session|
|
156
|
-
unless Neo4j::Label.constraint?(mapped_label_name, property)
|
157
|
-
label = Neo4j::Label.create(mapped_label_name)
|
158
|
-
drop_index(property, label) if index?(property)
|
159
|
-
label.create_constraint(property, constraints, session)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# @param [Symbol] property The name of the property index to be dropped
|
165
|
-
# @param [Neo4j::Label] label An instance of label from Neo4j::Core
|
166
|
-
def drop_index(property, label = nil)
|
167
|
-
label_obj = label || Neo4j::Label.create(mapped_label_name)
|
168
|
-
label_obj.drop_index(property)
|
169
|
-
end
|
170
|
-
|
171
|
-
# @param [Symbol] property The name of the property constraint to be dropped
|
172
|
-
# @param [Hash] constraint The constraint type to be dropped.
|
173
|
-
def drop_constraint(property, constraint = {type: :unique})
|
174
|
-
Neo4j::Session.on_session_available do |session|
|
175
|
-
label = Neo4j::Label.create(mapped_label_name)
|
176
|
-
label.drop_constraint(property, constraint, session)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def index?(index_def)
|
181
|
-
mapped_label.indexes[:property_keys].include?([index_def])
|
182
|
-
end
|
183
|
-
|
184
120
|
# @return [Array{Symbol}] all the labels that this class has
|
185
121
|
def mapped_label_names
|
186
122
|
self.ancestors.find_all { |a| a.respond_to?(:mapped_label_name) }.map { |a| a.mapped_label_name.to_sym }
|
@@ -196,10 +132,6 @@ module Neo4j
|
|
196
132
|
Neo4j::Label.create(mapped_label_name)
|
197
133
|
end
|
198
134
|
|
199
|
-
def indexed_properties
|
200
|
-
@_indexed_properties ||= []
|
201
|
-
end
|
202
|
-
|
203
135
|
def base_class
|
204
136
|
unless self < Neo4j::ActiveNode
|
205
137
|
fail "#{name} doesn't belong in a hierarchy descending from ActiveNode"
|
@@ -212,23 +144,8 @@ module Neo4j
|
|
212
144
|
end
|
213
145
|
end
|
214
146
|
|
215
|
-
|
216
147
|
protected
|
217
148
|
|
218
|
-
def _index(property, conf)
|
219
|
-
mapped_labels.each do |label|
|
220
|
-
# make sure the property is not indexed twice
|
221
|
-
existing = label.indexes[:property_keys]
|
222
|
-
|
223
|
-
# In neo4j constraint automatically creates an index
|
224
|
-
if conf[:constraint]
|
225
|
-
constraint(property, conf[:constraint])
|
226
|
-
else
|
227
|
-
label.create_index(property) unless existing.flatten.include?(property)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
149
|
def mapped_labels
|
233
150
|
mapped_label_names.map { |label_name| Neo4j::Label.create(label_name) }
|
234
151
|
end
|
@@ -247,17 +164,6 @@ module Neo4j
|
|
247
164
|
|
248
165
|
private
|
249
166
|
|
250
|
-
def find_callbacks!(result)
|
251
|
-
case result
|
252
|
-
when Neo4j::ActiveNode
|
253
|
-
result.run_callbacks(:find)
|
254
|
-
when Array
|
255
|
-
result.each { |r| find_callbacks!(r) }
|
256
|
-
else
|
257
|
-
result
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
167
|
def label_for_model
|
262
168
|
(self.name.nil? ? object_id.to_s.to_sym : decorated_label_name)
|
263
169
|
end
|