rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.07k stars 161 forks source link

Creating an array of relations only returns first saved element #561

Open mlk5060 opened 4 years ago

mlk5060 commented 4 years ago

Describe the bug

After following the repository quick start guide, specifically the create sub-section, I attempted to pass an array of hashes to the exposed create method on the repository. All array elements were saved to the datasource, but only the first saved element was returned.

To Reproduce

  1. Create a new class that inherits from ROM::Repository
  2. Add the commands :create macro to this class
  3. Attempt to save an array of hashes that represent the relation which the ROM::Repository defined in step 1 handles.
  4. Inspect the underlying datasource and return value of create

Expected behavior

Providing that no elements in the input array violate the underlying datasources constraints, all input array elements should be saved in the underlying datasource, and the return value of create should be an array whose size is equal to the input array, and contain representations of each tuple saved in the underlying datasource

Your environment

source "https://rubygems.org"

gem "rake"

# Web framework
gem "dry-system", "~> 0.9"
gem "dry-web", "~> 0.7"
gem "dry-web-roda", "~> 0.11"
gem "puma"
gem "rack_csrf"

gem "rack", ">= 2.0"

# Database persistence
gem "pg"
gem "rom", "~> 5.1"
gem "rom-sql", "~> 3.0.1"

# Application dependencies
gem "dry-matcher", "~> 0.8"
gem "dry-monads", "~> 1.3.0"
gem "dry-struct", "~> 1.0"
gem "dry-transaction", "~> 0.13"
gem "dry-types", "~> 1"
gem "dry-validation", "~> 1.2.1"
gem "dry-view", "~> 0.7"
gem "slim"

group :development, :test do
  gem "pry-byebug", platform: :mri
end

group :development do
  gem "rerun"
end

group :test do
  gem "capybara"
  gem "capybara-screenshot"
  gem "database_cleaner"
  gem "poltergeist"
  gem "rspec"
  gem "rom-factory", "~> 0.5"
end
solnic commented 4 years ago

For the record, this is happening because the underlying changeset command is configured using result: :one option

mlk5060 commented 4 years ago

Thanks for the clarification @solnic!