Navigation Menu

Skip to content

Commit

Permalink
Using cascade_delete for aggregate_each. [#72]
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Oct 18, 2009
1 parent a061862 commit fea37cb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Expand Up @@ -4,7 +4,7 @@ module AggregateEachNodeMixin
include Neo4j::NodeMixin
include Enumerable

has_list :groups, :counter => true
has_list :groups, :counter => true, :cascade_delete => :incoming

def aggregate_size
groups.size
Expand Down
4 changes: 1 addition & 3 deletions lib/neo4j/extensions/aggregate/aggregator_each.rb
Expand Up @@ -6,7 +6,7 @@ def initialize(root_node, nodes)
end

# Specifies which properties we should group on.
# All thos properties can be combined to create a new group.
# All those properties can be combined to create a new group.
#
# :api: public
def group_by(*keys)
Expand All @@ -17,12 +17,10 @@ def group_by(*keys)

def execute
@nodes.each do |node|
puts "agg #{node}"
group_node = GroupEachNode.new
group_node.group_by = @group_by.join(',')
group_node.aggregate = node
@root_node.groups << group_node
puts "agg #{node} done"
end
end
end
Expand Down
5 changes: 1 addition & 4 deletions lib/neo4j/extensions/aggregate/group_each_node.rb
Expand Up @@ -4,15 +4,12 @@ class GroupEachNode
include Neo4j::NodeMixin
include Enumerable

has_one :aggregate
has_one :aggregate, :cascade_delete => :incoming
property :aggregate_group, :aggregate_size, :group_by


def each
puts "each group #{group_by}"
puts "Agg node #{aggregate.props.inspect}"
group_by.split(',').each do |group|
puts "VALUE key='#{group}' vakye=#{aggregate[group]}'"
yield aggregate[group]
end
end
Expand Down
15 changes: 13 additions & 2 deletions test/extensions/aggregate_each_spec.rb
Expand Up @@ -43,11 +43,14 @@
agg1.should include(g1)
agg1.to_a.size.should == 4
agg1.aggregate_size.should == 4
sum = agg1.inject([]) {|s,g| g.inject(s) {|ss,n| ss << n}}
puts "sum=#{sum.inspect}"

agg1.map{|group| group[:age]}.should include(0,1,2,3)
end

it "should delete group if the node is deleted" do
pending "Need to fix lighthouse ticket 81 - Cascade delete on has_n, had_one and has_list first"
# pending "Need to fix lighthouse ticket 81 - Cascade delete on has_n, had_one and has_list first"

nodes = []
4.times {nodes << Neo4j::Node.new}
Expand All @@ -59,12 +62,20 @@
agg1 = AggregateEachNode.new
agg1.aggregate_each(nodes).group_by(:colour, :name).execute # TODO should not be needed to do execute
agg1.to_a.size.should == 4
agg1.aggregate_size.should == 4

# when
nodes[2].delete
#nodes[2].delete
n = nodes[2].aggregate_groups.to_a[0]
n.delete

Neo4j::Transaction.finish
Neo4j::Transaction.new

# then
agg1.each {|n| puts n}
agg1.to_a.size.should == 3
agg1.aggregate_size.should == 3
end


Expand Down

0 comments on commit fea37cb

Please sign in to comment.