module Orchestrate::Rails::Tutorial::GetGraph

Getting an Orchestrate.io graph

The films example application includes a feature to define a sequel relationship between films. This feature is implemented using graphs. Since orchestrate.io relations don't have a depth limit, we'll even be adding a method to get the sequel's sequel!

Updating the Film model for orchestrate.io graphs.

Update <rails-root>/app/models/film.rb to add the methods that get the film collection's sequel graph relations.

class Film < Orchestrate::Rails::Model

  def comments
    self.events('comments')
  end

  def sequels
    self.graph('sequel')
  end

  def spawn_of_sequels
    self.graph('sequel/sequel')
  end
end

Updating the films controller.

Update <rails-root>/app/controllers/films_controller.rb to call the sequel instance methods from the show action:

class FilmsController < ApplicationController

  def index
    @films = Film.all
  end

  def show
    @film = Film.find params[:id]
    @comments = @film.comments
    @sequels = @film.sequels
    @spawn_of_sequels = @film.spawn_of_sequels
  end
end

Updating the view to display sequel relations.

Update <rails-root>/app/views/films/show.html.haml as shown:

%ul.films.list-group
 %li.list-group-item
  %h3.list-group-item-heading= @film.title
  %ul.list-group
   %li.list-group-item
    = render partial: 'films/film_info'
   - if @sequels and @sequels.length > 0
    %li.list-group-item
     = render partial: 'films/film_list', locals: { title: "Sequels", films: @sequels }
   - if @spawn_of_sequels and @spawn_of_sequels.length > 0
    %li.list-group-item
     = render partial: 'films/film_list', locals: { title: "Sequel Spawn", films: @spawn_of_sequels }
   - if @comments and @comments.length > 0
    %li.list-group-item
     = render partial: 'films/comments', locals: { comments: @comments }

Let's check it out

Navigate to “The Godfather” to see its sequels.

If you ran the demo app to populate the collection, you can also check out “Star Wars”.

Next

Adding the create action