Skip to content

Instantly share code, notes, and snippets.

@borisaka
Forked from adz/graph_commands_in_rom.rb
Created February 4, 2017 10:26
Show Gist options
  • Select an option

  • Save borisaka/272543e1eac69aa6a56043fae4e4edbc to your computer and use it in GitHub Desktop.

Select an option

Save borisaka/272543e1eac69aa6a56043fae4e4edbc to your computer and use it in GitHub Desktop.

Revisions

  1. @adz adz revised this gist Jan 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion graph_commands_in_rom.rb
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    user_create = rom.command(:users)[:create]
    books_create = rom.comand(:books)[:create]
    nested_command = -> input {
    user_create.with(input[:user]).combine(
    user_create.call(input[:user]).combine(
    books_create.call(input[:user][:books])
    )
    }
  2. @adz adz created this gist Jan 13, 2016.
    21 changes: 21 additions & 0 deletions graph_commands_in_rom.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@

    command_builder = rom.command # no relation given, so get builder
    nested_command = command_builder.create(user: :users) do |user|
    user.create(:books)
    end

    # equivalent:
    nested_command = rom.command({user: :users}, [:create, [:books, [:create]]])

    # equivalent
    user_create = rom.command(:users)[:create]
    books_create = rom.comand(:books)[:create]
    nested_command = -> input {
    user_create.with(input[:user]).combine(
    books_create.call(input[:user][:books])
    )
    }

    # and books_create command is built to take (books, user)
    # and gets partially applied with :books, so on combine
    # it receives output of user_create command, which will be a user