Skip to content

Commit

Permalink
Fixed using traversal (Model#all) with Rails partials [neo4jrb#141 st…
Browse files Browse the repository at this point in the history
…ate: resolved]
  • Loading branch information
andreasronge committed Feb 1, 2011
1 parent 6eeef27 commit 8f70e28
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/neo4j/has_n/class_methods.rb
Expand Up @@ -44,7 +44,8 @@ module ClassMethods
#
# ==== Returns
#
# Neo4j::HasN::DeclRelationshipDsl
# * This method returns Neo4j::HasN::DeclRelationshipDsl
# * The generated has_n method returns a Neo4j::HasN::Mapping object
#
def has_n(rel_type, params = {})
clazz = self
Expand Down
13 changes: 9 additions & 4 deletions lib/neo4j/has_n/mapping.rb
Expand Up @@ -5,14 +5,14 @@
module Neo4j
module HasN

# Enables creating and traversal of nodes.
# The object created by a has_n or has_one Neo4j::NodeMixin class method which enables creating and traversal of nodes.
#
# Includes the Enumerable Mixin.
# Includes the Enumerable and WillPaginate mixins.
# The Neo4j::Mapping::ClassMethods::Relationship#has_n and Neo4j::Mapping::ClassMethods::Relationship#one
# methods returns an object of this type.
#
# ==== See Also
# Neo4j::Mapping::ClassMethods::Relationship
# Neo4j::HasN::ClassMethods
#
class Mapping
include Enumerable
Expand All @@ -31,7 +31,7 @@ def to_s
end

def size
[*self].size
self.to_a.size
end

alias_method :length, :size
Expand Down Expand Up @@ -60,6 +60,11 @@ def _each(&block)
@dsl.each_node(@node, @direction, true, &block)
end

# Returns an real ruby array.
def to_ary
self.to_a
end

def wp_query(options, pager, args, &block) #:nodoc:
page = pager.current_page || 1
to = pager.per_page * page
Expand Down
7 changes: 6 additions & 1 deletion lib/neo4j/traversal/traverser.rb
Expand Up @@ -47,6 +47,11 @@ def <<(other_node)
self
end

# Returns an real ruby array.
def to_ary
self.to_a
end

def new(other_node)
case @dir
when org.neo4j.graphdb.Direction::OUTGOING
Expand Down Expand Up @@ -130,7 +135,7 @@ def include_start_node
end

def size
[*self].size
to_a.size
end

alias_method :length, :size
Expand Down

0 comments on commit 8f70e28

Please sign in to comment.