Guest User

Untitled

a guest
Apr 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. require 'model' # from the example/imdb neo4j.rb example
  2.  
  3. class Actor
  4. def acted_in_cool_movies
  5. traverse.outgoing(:acted_in).find_all {|movie| movie.relationship?(:cool_movies, :incoming)}
  6. end
  7. end
  8.  
  9. cool_movies = Node.new
  10. all_cool_movies = [m1,m2] # m1,m2 are two movies - defined somewhere else
  11. all_cool_movies.each {|movie| cool_movies.relationships.outgoing(:cool_movies) << movie}
  12. cool_movies.traverse.outgoing(:cool_movies).incoming(:acted_in).depth(2).filter{ respond_to?(:acted_in_cool_movies) and acted_in_cool_movies.size == all_cool_movies.size}.each {|n| puts n}
  13.  
  14.  
  15. # Simple solution but inefficient solution
  16. m1.actors.to_a & m2.actors.to_a
Add Comment
Please, Sign In to add comment