neo4j 1.0.0.beta.12 → 1.0.0.beta.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,14 +64,18 @@ module Neo4j::Mapping
64
64
  clazz = self
65
65
  module_eval(%Q{def #{rel_type}=(value)
66
66
  dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
67
- rel = dsl.single_relationship(self)
67
+ dir = dsl.direction
68
+ dsl = dsl.incoming? ? dsl.incoming_dsl(self) : dsl
69
+ rel = dsl.single_relationship(self, dir)
68
70
  rel.del unless rel.nil?
69
71
  dsl.create_relationship_to(self, value)
70
72
  end}, __FILE__, __LINE__)
71
73
 
72
74
  module_eval(%Q{def #{rel_type}
73
75
  dsl = #{clazz}._decl_rels[:'#{rel_type.to_s}']
74
- dsl.single_relationship(self)
76
+ dir = dsl.direction
77
+ dsl = dsl.incoming? ? dsl.incoming_dsl(self) : dsl
78
+ dsl.single_relationship(self, dir)
75
79
  end}, __FILE__, __LINE__)
76
80
 
77
81
  # TODO
@@ -85,11 +85,23 @@ module Neo4j::Mapping
85
85
  end
86
86
  end
87
87
 
88
- def single_relationship(node)
88
+ def incoming?
89
+ @direction == :incoming
90
+ end
91
+
92
+ def incoming_dsl(node)
93
+ # which class specifies the incoming DSL ?
94
+ clazz = to_class || node.class
95
+ dsl = clazz._decl_rels[to_type]
96
+ raise "Unspecified outgoing relationship '#{to_type}' for incoming relationship '#{rel_id}' on class #{clazz}" if dsl.nil?
97
+ dsl
98
+ end
99
+
100
+ def single_relationship(node, dir)
89
101
  type = type_to_java(namespace_type)
90
- dir = dir_to_java(@direction)
102
+ dir = dir_to_java(dir)
91
103
  rel = node._java_node.getSingleRelationship(type, dir)
92
- rel.nil? ? nil : rel.end_node.wrapper
104
+ rel.nil? ? nil : rel.other_node(node).wrapper
93
105
  end
94
106
 
95
107
  def create_relationship_to(node, other)
@@ -11,15 +11,7 @@ module Neo4j
11
11
  def initialize(node, dsl) # :nodoc:
12
12
  @node = node
13
13
  @direction = dsl.direction
14
- # returns the other DSL if it exists otherwise use this DSL for specifying incoming relationships
15
- if @direction == :outgoing
16
- @dsl = dsl
17
- else
18
- # which class specifies the incoming DSL ?
19
- clazz = dsl.to_class || node.class
20
- @dsl = clazz._decl_rels[dsl.to_type]
21
- raise "Unspecified outgoing relationship '#{dsl.to_type}' for incoming relationship '#{dsl.rel_id}' on class #{clazz}" if @dsl.nil?
22
- end
14
+ @dsl = @direction == :outgoing ? dsl : dsl.incoming_dsl(node)
23
15
  end
24
16
 
25
17
  def to_s
@@ -137,7 +137,6 @@ module Neo4j
137
137
  # Check if we want to destroy not found nodes (e.g. {..., :_destroy => '1' } ?
138
138
  destroy = attr[:_destroy] && attr[:_destroy] != '0'
139
139
 
140
- puts "FOUND #{found}"
141
140
  if found
142
141
  if destroy
143
142
  found.destroy if allow_destroy
@@ -67,7 +67,6 @@ module Neo4j::Rails
67
67
  rel.each do |new_node|
68
68
  wrapper = new_node.respond_to?(:wrapper) ? new_node.wrapper : new_node
69
69
  if wrapper.save
70
- puts "NEW RELATIONSHIP OF TYPE #{type} from #{root_node} to #{new_node}"
71
70
  root_node.outgoing(type) << wrapper
72
71
  else
73
72
  valid = false
@@ -90,9 +89,11 @@ module Neo4j::Rails
90
89
  self
91
90
  end
92
91
 
93
- def getOtherNode(other)
92
+ def other_node(other)
94
93
  other == @end_node ? @start_node : @end_node
95
94
  end
95
+
96
+ alias_method :getOtherNode, :other_node
96
97
  end
97
98
 
98
99
 
data/lib/neo4j/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neo4j
2
- VERSION = "1.0.0.beta.12"
2
+ VERSION = "1.0.0.beta.13"
3
3
  end
metadata CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
7
7
  - 0
8
8
  - 0
9
9
  - beta
10
- - 12
11
- version: 1.0.0.beta.12
10
+ - 13
11
+ version: 1.0.0.beta.13
12
12
  platform: ruby
13
13
  authors:
14
14
  - Andreas Ronge