activegraph 10.0.0.pre.alpha.11 → 10.0.0.pre.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/{neo4j.gemspec → activegraph.gemspec} +7 -9
- data/config/neo4j/config.yml +4 -4
- data/lib/active_graph.rb +120 -0
- data/lib/{neo4j → active_graph}/ansi.rb +1 -1
- data/lib/{neo4j → active_graph}/attribute_set.rb +3 -3
- data/lib/{neo4j/active_base.rb → active_graph/base.rb} +18 -12
- data/lib/{neo4j → active_graph}/class_arguments.rb +5 -5
- data/lib/{neo4j → active_graph}/config.rb +10 -10
- data/lib/active_graph/core.rb +14 -0
- data/lib/{neo4j → active_graph}/core/connection_failed_error.rb +1 -1
- data/lib/{neo4j → active_graph}/core/cypher_error.rb +1 -1
- data/lib/{neo4j → active_graph}/core/driver.rb +5 -5
- data/lib/{neo4j → active_graph}/core/has_uri.rb +1 -1
- data/lib/{neo4j → active_graph}/core/instrumentable.rb +4 -4
- data/lib/{neo4j → active_graph}/core/label.rb +13 -13
- data/lib/{neo4j → active_graph}/core/logging.rb +2 -2
- data/lib/{neo4j → active_graph}/core/node.rb +2 -2
- data/lib/{neo4j → active_graph}/core/querable.rb +7 -7
- data/lib/{neo4j → active_graph}/core/query.rb +16 -16
- data/lib/{neo4j → active_graph}/core/query_builder.rb +3 -3
- data/lib/{neo4j → active_graph}/core/query_clauses.rb +1 -1
- data/lib/{neo4j → active_graph}/core/query_ext.rb +5 -5
- data/lib/{neo4j → active_graph}/core/query_find_in_batches.rb +2 -2
- data/lib/{neo4j → active_graph}/core/relationship.rb +2 -2
- data/lib/{neo4j → active_graph}/core/responses.rb +3 -3
- data/lib/{neo4j → active_graph}/core/result.rb +1 -1
- data/lib/{neo4j → active_graph}/core/schema.rb +1 -1
- data/lib/{neo4j → active_graph}/core/schema_errors.rb +1 -1
- data/lib/{neo4j → active_graph}/core/wrappable.rb +1 -1
- data/lib/{neo4j → active_graph}/errors.rb +1 -1
- data/lib/{neo4j → active_graph}/lazy_attribute_hash.rb +1 -1
- data/lib/{neo4j → active_graph}/migration.rb +11 -11
- data/lib/{neo4j → active_graph}/migrations.rb +5 -5
- data/lib/{neo4j → active_graph}/migrations/base.rb +7 -7
- data/lib/{neo4j → active_graph}/migrations/check_pending.rb +3 -3
- data/lib/{neo4j → active_graph}/migrations/helpers.rb +4 -4
- data/lib/{neo4j → active_graph}/migrations/helpers/id_property.rb +3 -3
- data/lib/{neo4j → active_graph}/migrations/helpers/relationships.rb +1 -1
- data/lib/{neo4j → active_graph}/migrations/helpers/schema.rb +7 -7
- data/lib/{neo4j → active_graph}/migrations/migration_file.rb +1 -1
- data/lib/{neo4j → active_graph}/migrations/runner.rb +3 -3
- data/lib/{neo4j → active_graph}/migrations/schema.rb +1 -1
- data/lib/{neo4j → active_graph}/migrations/schema_migration.rb +2 -2
- data/lib/{neo4j → active_graph}/model_schema.rb +8 -8
- data/lib/{neo4j/active_node.rb → active_graph/node.rb} +32 -32
- data/lib/{neo4j/active_node → active_graph/node}/callbacks.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/dependent.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/dependent/association_methods.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/dependent/query_proxy_methods.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/dependent_callbacks.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/enum.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/has_n.rb +20 -20
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association.rb +8 -8
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association/rel_factory.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association/rel_wrapper.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/has_n/association_cypher_methods.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/id_property.rb +7 -7
- data/lib/{neo4j/active_node → active_graph/node}/id_property/accessor.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/initialize.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/labels.rb +18 -18
- data/lib/{neo4j/active_node → active_graph/node}/labels/index.rb +6 -6
- data/lib/{neo4j/active_node → active_graph/node}/labels/reloading.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/node_list_formatter.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/node_wrapper.rb +5 -5
- data/lib/{neo4j/active_node → active_graph/node}/orm_adapter.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/persistence.rb +7 -7
- data/lib/{neo4j/active_node → active_graph/node}/property.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/query.rb +9 -9
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy.rb +19 -19
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_eager_loading.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_eager_loading/association_tree.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_enumerable.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_find_in_batches.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_link.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_methods.rb +12 -12
- data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_methods_of_mass_updating.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/query_methods.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/reflection.rb +3 -3
- data/lib/{neo4j/active_node → active_graph/node}/rels.rb +1 -1
- data/lib/{neo4j/active_node → active_graph/node}/scope.rb +4 -4
- data/lib/{neo4j/active_node → active_graph/node}/unpersisted.rb +2 -2
- data/lib/{neo4j/active_node → active_graph/node}/validations.rb +3 -3
- data/lib/{neo4j → active_graph}/paginated.rb +1 -1
- data/lib/{neo4j → active_graph}/railtie.rb +18 -18
- data/lib/{neo4j/active_rel.rb → active_graph/relationship.rb} +19 -19
- data/lib/active_graph/relationship/callbacks.rb +21 -0
- data/lib/{neo4j/active_rel → active_graph/relationship}/initialize.rb +5 -5
- data/lib/{neo4j/active_rel → active_graph/relationship}/persistence.rb +6 -6
- data/lib/{neo4j/active_rel → active_graph/relationship}/persistence/query_factory.rb +7 -7
- data/lib/{neo4j/active_rel → active_graph/relationship}/property.rb +6 -6
- data/lib/{neo4j/active_rel → active_graph/relationship}/query.rb +7 -7
- data/lib/{neo4j/active_rel → active_graph/relationship}/rel_wrapper.rb +5 -5
- data/lib/{neo4j/active_rel → active_graph/relationship}/related_node.rb +7 -7
- data/lib/{neo4j/active_rel → active_graph/relationship}/types.rb +6 -6
- data/lib/active_graph/relationship/validations.rb +8 -0
- data/lib/{neo4j → active_graph}/schema/operation.rb +5 -5
- data/lib/{neo4j → active_graph}/shared.rb +7 -7
- data/lib/{neo4j → active_graph}/shared/attributes.rb +10 -10
- data/lib/{neo4j → active_graph}/shared/callbacks.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/cypher.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/declared_properties.rb +8 -8
- data/lib/{neo4j → active_graph}/shared/declared_property.rb +9 -9
- data/lib/{neo4j → active_graph}/shared/declared_property/index.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/enum.rb +6 -6
- data/lib/{neo4j → active_graph}/shared/filtered_hash.rb +2 -2
- data/lib/{neo4j → active_graph}/shared/identity.rb +2 -2
- data/lib/{neo4j → active_graph}/shared/initialize.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/marshal.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/mass_assignment.rb +2 -2
- data/lib/{neo4j → active_graph}/shared/permitted_attributes.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/persistence.rb +4 -4
- data/lib/{neo4j → active_graph}/shared/property.rb +10 -10
- data/lib/{neo4j → active_graph}/shared/query_factory.rb +5 -5
- data/lib/{neo4j → active_graph}/shared/rel_type_converters.rb +6 -6
- data/lib/{neo4j → active_graph}/shared/serialized_properties.rb +1 -1
- data/lib/{neo4j → active_graph}/shared/type_converters.rb +11 -13
- data/lib/{neo4j → active_graph}/shared/typecasted_attributes.rb +7 -7
- data/lib/{neo4j → active_graph}/shared/typecaster.rb +3 -3
- data/lib/{neo4j → active_graph}/shared/validations.rb +1 -1
- data/lib/{neo4j → active_graph}/tasks/migration.rake +25 -25
- data/lib/{neo4j → active_graph}/timestamps.rb +3 -3
- data/lib/{neo4j → active_graph}/timestamps/created.rb +1 -1
- data/lib/{neo4j → active_graph}/timestamps/updated.rb +1 -1
- data/lib/{neo4j → active_graph}/transaction.rb +9 -9
- data/lib/active_graph/transactions.rb +54 -0
- data/lib/{neo4j → active_graph}/type_converters.rb +2 -2
- data/lib/{neo4j → active_graph}/undeclared_properties.rb +1 -1
- data/lib/active_graph/version.rb +3 -0
- data/lib/{neo4j → active_graph}/wrapper.rb +1 -1
- data/lib/rails/generators/neo4j/migration/migration_generator.rb +4 -4
- data/lib/rails/generators/neo4j/migration/templates/migration.erb +2 -2
- data/lib/rails/generators/neo4j/model/model_generator.rb +4 -4
- data/lib/rails/generators/neo4j/model/templates/migration.erb +1 -1
- data/lib/rails/generators/neo4j/model/templates/model.erb +1 -1
- data/lib/rails/generators/neo4j/upgrade_v8/templates/migration.erb +1 -1
- data/lib/rails/generators/neo4j/upgrade_v8/upgrade_v8_generator.rb +6 -6
- data/lib/rails/generators/neo4j_generator.rb +4 -4
- metadata +134 -133
- data/lib/neo4j.rb +0 -119
- data/lib/neo4j/active_rel/callbacks.rb +0 -21
- data/lib/neo4j/active_rel/validations.rb +0 -8
- data/lib/neo4j/core.rb +0 -14
- data/lib/neo4j/version.rb +0 -3
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'active_support/inflector'
|
2
|
-
require '
|
2
|
+
require 'active_graph/core/node'
|
3
3
|
|
4
4
|
wrapping_proc = proc do |node|
|
5
|
-
found_class =
|
5
|
+
found_class = ActiveGraph::NodeWrapping.class_to_wrap(node.labels)
|
6
6
|
next node if not found_class
|
7
7
|
|
8
8
|
found_class.new.tap do |wrapped_node|
|
@@ -11,7 +11,7 @@ wrapping_proc = proc do |node|
|
|
11
11
|
end
|
12
12
|
Neo4j::Driver::Types::Node.wrapper_callback(wrapping_proc)
|
13
13
|
|
14
|
-
module
|
14
|
+
module ActiveGraph
|
15
15
|
module NodeWrapping
|
16
16
|
# Only load classes once for performance
|
17
17
|
CONSTANTS_FOR_LABELS_CACHE = {}
|
@@ -19,7 +19,7 @@ module Neo4j
|
|
19
19
|
class << self
|
20
20
|
def class_to_wrap(labels)
|
21
21
|
load_classes_from_labels(labels)
|
22
|
-
|
22
|
+
ActiveGraph::Node::Labels.model_for_labels(labels).tap do |model_class|
|
23
23
|
populate_constants_for_labels_cache(model_class, labels)
|
24
24
|
end
|
25
25
|
end
|
@@ -47,7 +47,7 @@ module Neo4j
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def association_model_namespace
|
50
|
-
|
50
|
+
ActiveGraph::Config.association_model_namespace_string
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Node
|
2
2
|
module Persistence
|
3
3
|
class RecordInvalidError < RuntimeError
|
4
4
|
attr_reader :record
|
@@ -11,7 +11,7 @@ module Neo4j::ActiveNode
|
|
11
11
|
|
12
12
|
extend ActiveSupport::Concern
|
13
13
|
extend Forwardable
|
14
|
-
include
|
14
|
+
include ActiveGraph::Shared::Persistence
|
15
15
|
|
16
16
|
# Saves the model.
|
17
17
|
#
|
@@ -41,11 +41,11 @@ module Neo4j::ActiveNode
|
|
41
41
|
# to #save! Creates a new transaction.
|
42
42
|
#
|
43
43
|
# @raise a RecordInvalidError if there is a problem during save.
|
44
|
-
# @param (see
|
44
|
+
# @param (see ActiveGraph::Rails::Validations#save)
|
45
45
|
# @return nil
|
46
46
|
# @see #save
|
47
|
-
# @see
|
48
|
-
# @see
|
47
|
+
# @see ActiveGraph::Rails::Validations ActiveGraph::Rails::Validations - for the :validate parameter
|
48
|
+
# @see ActiveGraph::Rails::Callbacks ActiveGraph::Rails::Callbacks - for callbacks
|
49
49
|
def save!(*args)
|
50
50
|
save(*args) or fail(RecordInvalidError, self) # rubocop:disable Style/AndOr
|
51
51
|
end
|
@@ -64,7 +64,7 @@ module Neo4j::ActiveNode
|
|
64
64
|
# Creates an unwrapped node in the database.
|
65
65
|
# @param [Hash] node_props The type-converted properties to be added to the new node.
|
66
66
|
# @param [Array] labels The labels to use for creating the new node.
|
67
|
-
# @return [
|
67
|
+
# @return [ActiveGraph::Node] A CypherNode or EmbeddedNode
|
68
68
|
def _create_node(node_props, labels = labels_for_create)
|
69
69
|
query = "CREATE (n:`#{Array(labels).join('`:`')}`) SET n = $props RETURN n"
|
70
70
|
neo4j_query(query, {props: node_props}, wrap_level: :core_entity).to_a[0].n
|
@@ -162,7 +162,7 @@ module Neo4j::ActiveNode
|
|
162
162
|
end
|
163
163
|
|
164
164
|
def query_base_for(neo_id, var = :n)
|
165
|
-
|
165
|
+
ActiveGraph::Base.new_query.match(var).where(var => {neo_id: neo_id})
|
166
166
|
end
|
167
167
|
|
168
168
|
private
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module
|
1
|
+
module ActiveGraph::Node
|
2
2
|
module Property
|
3
3
|
extend ActiveSupport::Concern
|
4
|
-
include
|
4
|
+
include ActiveGraph::Shared::Property
|
5
5
|
|
6
6
|
def initialize(attributes = nil)
|
7
7
|
super(attributes)
|
8
|
-
@attributes ||=
|
8
|
+
@attributes ||= ActiveGraph::AttributeSet.new(self.class.attributes_nil_hash, self.class.attributes.keys)
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module
|
2
|
-
module
|
3
|
-
# Helper methods to return
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
|
+
# Helper methods to return ActiveGraph::Core::Query objects. A query object can be used to successively build a cypher query
|
4
4
|
#
|
5
5
|
# person.query_as(:n).match('n-[:friend]-o').return(o: :name) # Return the names of all the person's friends
|
6
6
|
#
|
@@ -14,7 +14,7 @@ module Neo4j
|
|
14
14
|
# mike.query_as(:mike).match('mike-[:friend]-friend').return(friend: :name)
|
15
15
|
#
|
16
16
|
# @param node_var [Symbol, String] The variable name to specify in the query
|
17
|
-
# @return [
|
17
|
+
# @return [ActiveGraph::Core::Query]
|
18
18
|
def query_as(node_var)
|
19
19
|
self.class.query_as(node_var, false).where("ID(#{node_var})" => self.neo_id)
|
20
20
|
end
|
@@ -27,7 +27,7 @@ module Neo4j
|
|
27
27
|
# student.as(:s).lessons(:l)
|
28
28
|
#
|
29
29
|
# @param [String, Symbol] node_var The identifier to use within the QueryProxy object
|
30
|
-
# @return [
|
30
|
+
# @return [ActiveGraph::Node::Query::QueryProxy]
|
31
31
|
def as(node_var)
|
32
32
|
self.class.query_proxy(node: node_var, source_object: self).match_to(self)
|
33
33
|
end
|
@@ -42,19 +42,19 @@ module Neo4j
|
|
42
42
|
# @param [Symbol, String] var The variable name to specify in the query
|
43
43
|
# @param [Boolean] with_labels Should labels be used to build the match? There are situations (neo_id used to filter,
|
44
44
|
# an early Cypher match has already filtered results) where including labels will degrade performance.
|
45
|
-
# @return [
|
45
|
+
# @return [ActiveGraph::Core::Query]
|
46
46
|
def query_as(var, with_labels = true)
|
47
47
|
query_proxy.query_as(var, with_labels)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
ActiveGraph::Node::Query::QueryProxy::METHODS.each do |method|
|
51
51
|
define_method(method) do |*args|
|
52
52
|
self.query_proxy.send(method, *args)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def query_proxy(options = {})
|
57
|
-
|
57
|
+
ActiveGraph::Node::Query::QueryProxy.new(self, nil, options)
|
58
58
|
end
|
59
59
|
|
60
60
|
# Start a new QueryProxy with the starting identifier set to the given argument.
|
@@ -66,7 +66,7 @@ module Neo4j
|
|
66
66
|
# Student.as(:s).lessons
|
67
67
|
#
|
68
68
|
# @param [String, Symbol] node_var A string or symbol to use as the starting identifier.
|
69
|
-
# @return [
|
69
|
+
# @return [ActiveGraph::Node::Query::QueryProxy]
|
70
70
|
def as(node_var)
|
71
71
|
query_proxy(node: node_var, context: self.name)
|
72
72
|
end
|
@@ -1,32 +1,32 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
3
|
module Query
|
4
4
|
# rubocop:disable Metrics/ClassLength
|
5
5
|
class QueryProxy
|
6
6
|
# rubocop:enable Metrics/ClassLength
|
7
|
-
include
|
8
|
-
include
|
9
|
-
include
|
10
|
-
include
|
11
|
-
include
|
12
|
-
include
|
7
|
+
include ActiveGraph::Node::Query::QueryProxyEnumerable
|
8
|
+
include ActiveGraph::Node::Query::QueryProxyMethods
|
9
|
+
include ActiveGraph::Node::Query::QueryProxyMethodsOfMassUpdating
|
10
|
+
include ActiveGraph::Node::Query::QueryProxyFindInBatches
|
11
|
+
include ActiveGraph::Node::Query::QueryProxyEagerLoading
|
12
|
+
include ActiveGraph::Node::Dependent::QueryProxyMethods
|
13
13
|
|
14
14
|
# The most recent node to start a QueryProxy chain.
|
15
15
|
# Will be nil when using QueryProxy chains on class methods.
|
16
16
|
attr_reader :source_object, :association, :model, :starting_query
|
17
17
|
|
18
|
-
# QueryProxy is
|
19
|
-
# it is actually referring to <tt>
|
18
|
+
# QueryProxy is Node's Cypher DSL. While the name might imply that it creates queries in a general sense,
|
19
|
+
# it is actually referring to <tt>ActiveGraph::Core::Query</tt>, which is a pure Ruby Cypher DSL provided by the <tt>neo4j-core</tt> gem.
|
20
20
|
# QueryProxy provides ActiveRecord-like methods for common patterns. When it's not handling CRUD for relationships and queries, it
|
21
|
-
# provides
|
21
|
+
# provides Node's association chaining (`student.lessons.teachers.where(age: 30).hobbies`) and enjoys long walks on the
|
22
22
|
# beach.
|
23
23
|
#
|
24
24
|
# It should not ever be necessary to instantiate a new QueryProxy object directly, it always happens as a result of
|
25
25
|
# calling a method that makes use of it.
|
26
26
|
#
|
27
|
-
# @param [Constant] model The class which included
|
27
|
+
# @param [Constant] model The class which included Node (typically a model, hence the name) from which the query
|
28
28
|
# originated.
|
29
|
-
# @param [
|
29
|
+
# @param [ActiveGraph::Node::HasN::Association] association The Node association (an object created by a <tt>has_one</tt> or
|
30
30
|
# <tt>has_many</tt>) that created this object.
|
31
31
|
# @param [Hash] options Additional options pertaining to the QueryProxy object. These may include:
|
32
32
|
# @option options [String, Symbol] :node_var A string or symbol to be used by Cypher within its query string as an identifier
|
@@ -34,7 +34,7 @@ module Neo4j
|
|
34
34
|
# @option options [Range, Integer, Symbol, Hash] :rel_length A Range, a Integer, a Hash or a Symbol to indicate the variable-length/fixed-length
|
35
35
|
# qualifier of the relationship. See http://neo4jrb.readthedocs.org/en/latest/Querying.html#variable-length-relationships.
|
36
36
|
# @option options [Neo4j::Driver] :driver The driver to be used for this query
|
37
|
-
# @option options [
|
37
|
+
# @option options [ActiveGraph::Node] :source_object The node instance at the start of the QueryProxy chain
|
38
38
|
# @option options [QueryProxy] :query_proxy An existing QueryProxy chain upon which this new object should be built
|
39
39
|
#
|
40
40
|
# QueryProxy objects are evaluated lazily.
|
@@ -56,7 +56,7 @@ module Neo4j
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def inspect
|
59
|
-
formatted_nodes =
|
59
|
+
formatted_nodes = ActiveGraph::Node::NodeListFormatter.new(to_a)
|
60
60
|
"#<QueryProxy #{@context} #{formatted_nodes.inspect}>"
|
61
61
|
end
|
62
62
|
|
@@ -87,8 +87,8 @@ module Neo4j
|
|
87
87
|
query_as(identity)
|
88
88
|
end
|
89
89
|
|
90
|
-
# Build a
|
91
|
-
# and work with it from the more powerful (but less friendly)
|
90
|
+
# Build a ActiveGraph::Core::Query object for the QueryProxy. This is necessary when you want to take an existing QueryProxy chain
|
91
|
+
# and work with it from the more powerful (but less friendly) ActiveGraph::Core::Query.
|
92
92
|
# @param [String,Symbol] var The identifier to use for node at this link of the QueryProxy chain.
|
93
93
|
#
|
94
94
|
# .. code-block:: ruby
|
@@ -205,7 +205,7 @@ module Neo4j
|
|
205
205
|
fail 'Can only create relationships on associations' if !@association
|
206
206
|
other_nodes = _nodeify!(*other_nodes)
|
207
207
|
|
208
|
-
|
208
|
+
ActiveGraph::Base.run_transaction do
|
209
209
|
other_nodes.each do |other_node|
|
210
210
|
if other_node.neo_id
|
211
211
|
other_node.try(:delete_reverse_has_one_core_rel, association)
|
@@ -310,7 +310,7 @@ module Neo4j
|
|
310
310
|
end
|
311
311
|
|
312
312
|
def _query
|
313
|
-
|
313
|
+
ActiveGraph::Base.new_query(context: @context)
|
314
314
|
end
|
315
315
|
|
316
316
|
def _result_string(index = nil)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
3
|
module Query
|
4
4
|
module QueryProxyEagerLoading
|
5
5
|
class IdentityMap < Hash
|
@@ -59,7 +59,7 @@ module Neo4j
|
|
59
59
|
def add_to_cache(rel, node, element)
|
60
60
|
direction = element.association.direction
|
61
61
|
node = cache_and_init(node, element)
|
62
|
-
if rel.is_a?(
|
62
|
+
if rel.is_a?(ActiveGraph::Relationship)
|
63
63
|
rel.instance_variable_set(direction == :in ? '@from_node' : '@to_node', node)
|
64
64
|
end
|
65
65
|
@_cache[direction == :out ? rel.start_node_neo_id : rel.end_node_neo_id]
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
3
|
module Query
|
4
4
|
# Methods related to returning nodes and rels from QueryProxy
|
5
5
|
module QueryProxyEnumerable
|
@@ -69,7 +69,7 @@ module Neo4j
|
|
69
69
|
def pluck(*args)
|
70
70
|
transformable_attributes = (model ? model.attribute_names : []) + %w(uuid neo_id)
|
71
71
|
arg_list = args.map do |arg|
|
72
|
-
arg =
|
72
|
+
arg = ActiveGraph::Node::Query::QueryProxy::Link.converted_key(model, arg)
|
73
73
|
if transformable_attributes.include?(arg.to_s)
|
74
74
|
{identity => arg}
|
75
75
|
else
|
@@ -99,7 +99,7 @@ module Neo4j
|
|
99
99
|
instance.each do |object|
|
100
100
|
object.instance_variable_set('@source_query_proxy', self)
|
101
101
|
object.instance_variable_set('@source_proxy_result_cache', instance)
|
102
|
-
if node && rel && object.last.is_a?(
|
102
|
+
if node && rel && object.last.is_a?(ActiveGraph::Relationship)
|
103
103
|
object.last.instance_variable_set(association.direction == :in ? '@from_node' : '@to_node', object.first)
|
104
104
|
end
|
105
105
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
3
|
module Query
|
4
4
|
class QueryProxy
|
5
5
|
class Link
|
@@ -56,7 +56,7 @@ module Neo4j
|
|
56
56
|
|
57
57
|
val = if !model
|
58
58
|
value
|
59
|
-
elsif key == model.id_property_name && value.is_a?(
|
59
|
+
elsif key == model.id_property_name && value.is_a?(ActiveGraph::Node)
|
60
60
|
value.id
|
61
61
|
else
|
62
62
|
converted_value(model, key, value)
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
3
|
module Query
|
4
4
|
# rubocop:disable Metrics/ModuleLength
|
5
5
|
module QueryProxyMethods
|
@@ -54,7 +54,7 @@ module Neo4j
|
|
54
54
|
# @return [Integer] number of nodes of this class
|
55
55
|
def count(distinct = nil, target = nil)
|
56
56
|
return 0 if unpersisted_start_object?
|
57
|
-
fail(
|
57
|
+
fail(ActiveGraph::InvalidParameterError, ':count accepts the `:distinct` symbol or nil as a parameter') unless distinct.nil? || distinct == :distinct
|
58
58
|
query_with_target(target) do |var|
|
59
59
|
q = ensure_distinct(var, !distinct.nil?)
|
60
60
|
limited_query = self.query.clause?(:limit) ? self.query.break.with(var) : self.query.reorder
|
@@ -71,7 +71,7 @@ module Neo4j
|
|
71
71
|
# TODO: update this with public API methods if/when they are exposed
|
72
72
|
def limit_value
|
73
73
|
return unless self.query.clause?(:limit)
|
74
|
-
limit_clause = self.query.send(:clauses).find { |clause| clause.is_a?(
|
74
|
+
limit_clause = self.query.send(:clauses).find { |clause| clause.is_a?(ActiveGraph::Core::QueryClauses::LimitClause) }
|
75
75
|
limit_clause.instance_variable_get(:@arg)
|
76
76
|
end
|
77
77
|
|
@@ -82,7 +82,7 @@ module Neo4j
|
|
82
82
|
|
83
83
|
alias blank? empty?
|
84
84
|
|
85
|
-
# @param [
|
85
|
+
# @param [ActiveGraph::Node, ActiveGraph::Node, String] other An instance of a Neo4j.rb model, a Neo4j-core node, or a string uuid
|
86
86
|
# @param [String, Symbol] target An identifier of a link in the Cypher chain
|
87
87
|
# @return [Boolean]
|
88
88
|
def include?(other, target = nil)
|
@@ -99,7 +99,7 @@ module Neo4j
|
|
99
99
|
|
100
100
|
def exists?(node_condition = nil, target = nil)
|
101
101
|
unless [Integer, String, Hash, NilClass].any? { |c| node_condition.is_a?(c) }
|
102
|
-
fail(
|
102
|
+
fail(ActiveGraph::InvalidParameterError, ':exists? only accepts ids or conditions')
|
103
103
|
end
|
104
104
|
query_with_target(target) do |var|
|
105
105
|
start_q = exists_query_start(node_condition, var)
|
@@ -109,12 +109,12 @@ module Neo4j
|
|
109
109
|
end
|
110
110
|
|
111
111
|
# Shorthand for `MATCH (start)-[r]-(other_node) WHERE ID(other_node) = #{other_node.neo_id}`
|
112
|
-
# The `node` param can be a persisted
|
112
|
+
# The `node` param can be a persisted Node instance, any string or integer, or nil.
|
113
113
|
# When it's a node, it'll use the object's neo_id, which is fastest. When not nil, it'll figure out the
|
114
114
|
# primary key of that model. When nil, it uses `1 = 2` to prevent matching all records, which is the default
|
115
115
|
# behavior when nil is passed to `where` in QueryProxy.
|
116
116
|
# @param [#neo_id, String, Enumerable] node A node, a string representing a node's ID, or an enumerable of nodes or IDs.
|
117
|
-
# @return [
|
117
|
+
# @return [ActiveGraph::Node::Query::QueryProxy] A QueryProxy object upon which you can build.
|
118
118
|
def match_to(node)
|
119
119
|
first_node = node.is_a?(Array) ? node.first : node
|
120
120
|
where_arg = if first_node.respond_to?(:neo_id)
|
@@ -133,7 +133,7 @@ module Neo4j
|
|
133
133
|
# Gives you the first relationship between the last link of a QueryProxy chain and a given node
|
134
134
|
# Shorthand for `MATCH (start)-[r]-(other_node) WHERE ID(other_node) = #{other_node.neo_id} RETURN r`
|
135
135
|
# @param [#neo_id, String, Enumerable] node An object to be sent to `match_to`. See params for that method.
|
136
|
-
# @return A relationship (
|
136
|
+
# @return A relationship (Relationship, CypherRelationship, EmbeddedRelationship) or nil.
|
137
137
|
def first_rel_to(node)
|
138
138
|
self.match_to(node).limit(1).pluck(rel_var).first
|
139
139
|
end
|
@@ -152,7 +152,7 @@ module Neo4j
|
|
152
152
|
fail 'Method invalid when called on Class objects' unless source_object
|
153
153
|
result = self.where(params).first
|
154
154
|
return result unless result.nil?
|
155
|
-
|
155
|
+
ActiveGraph::Base.run_transaction do
|
156
156
|
node = model.create(params)
|
157
157
|
self << node
|
158
158
|
return node
|
@@ -172,7 +172,7 @@ module Neo4j
|
|
172
172
|
self.send(association, node_var, rel_var, optional: true)
|
173
173
|
end
|
174
174
|
|
175
|
-
# Takes an Array of
|
175
|
+
# Takes an Array of Node models and applies the appropriate WHERE clause
|
176
176
|
# So for a `Teacher` model inheriting from a `Person` model and an `Article` model
|
177
177
|
# if you called .as_models([Teacher, Article])
|
178
178
|
# The where clause would look something like:
|
@@ -250,7 +250,7 @@ module Neo4j
|
|
250
250
|
end
|
251
251
|
|
252
252
|
def where_clause_params
|
253
|
-
query.clauses.select { |c| c.is_a?(
|
253
|
+
query.clauses.select { |c| c.is_a?(ActiveGraph::Core::QueryClauses::WhereClause) && c.arg.is_a?(Hash) }
|
254
254
|
.map! { |e| e.arg[identity] }.compact.inject { |a, b| a.merge(b) } || {}
|
255
255
|
end
|
256
256
|
|
data/lib/{neo4j/active_node → active_graph/node}/query/query_proxy_methods_of_mass_updating.rb
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module ActiveGraph
|
2
|
+
module Node
|
3
3
|
module Query
|
4
4
|
module QueryProxyMethodsOfMassUpdating
|
5
5
|
# Updates some attributes of a group of nodes within a QP chain.
|
@@ -7,7 +7,7 @@ module Neo4j
|
|
7
7
|
# @param [Hash,String] updates An hash or a string of parameters to be updated.
|
8
8
|
# @param [Hash] params An hash of parameters for the update string. It's ignored if `updates` is an Hash.
|
9
9
|
def update_all(updates, params = {})
|
10
|
-
# Move this to
|
10
|
+
# Move this to Node module?
|
11
11
|
update_all_with_query(identity, updates, params)
|
12
12
|
end
|
13
13
|
|
@@ -27,7 +27,7 @@ module Neo4j
|
|
27
27
|
query_with_target(identifier) do |target|
|
28
28
|
begin
|
29
29
|
self.query.with(target).optional_match("(#{target})-[#{target}_rel]-()").delete("#{target}, #{target}_rel").exec
|
30
|
-
rescue
|
30
|
+
rescue ActiveGraph::Core::CypherError # <=- Seems hacky
|
31
31
|
self.query.delete(target).exec
|
32
32
|
end
|
33
33
|
clear_source_object_cache
|