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.
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.call(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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment