# Delete command on relation should return all deleted entities

**URL:** <https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228>\
**Category:** Issues\
**Created:** [April 9, 2018, 11:59am UTC](https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228 "2018-04-09T11:59:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelvh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/joelvh/32/139_2.png) [@joelvh](https://discourse.rom-rb.org/u/joelvh)\
**Post date:** [April 9, 2018, 11:59am UTC](https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228/1 "2018-04-09T11:59:23Z")

</div>

According to the [code comments](https://github.com/rom-rb/rom-sql/blob/master/lib/rom/sql/commands/delete.rb#L16), the delete command should return the deleted entities. However, they return one.

```ruby
relation.changeset(:create, {id: 1}, {id: 2}, {id: 3}).commit

result = relation.command(:delete).call
# => #<ROM::Struct::Event id="1">

```

That should be an array of all 3 entities, correct?

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/solnic/32/279_2.png) [@solnic](https://discourse.rom-rb.org/u/solnic)\
**Post date:** [April 9, 2018, 12:00pm UTC](https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228/2 "2018-04-09T12:00:49Z")

</div>

Hmm, does it work when you do `relation.command(:delete, result: :many).call`?

---

<div class="post-metadata">

**Author:** ![joelvh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/joelvh/32/139_2.png) [@joelvh](https://discourse.rom-rb.org/u/joelvh)\
**Post date:** [April 13, 2018, 12:14am UTC](https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228/3 "2018-04-13T00:14:43Z")

</div>

Hi @solnic - that solved it. However, it’s odd that the source describes and implies a different result?

---

<div class="post-metadata">

**Author:** ![joelvh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/joelvh/32/139_2.png) [@joelvh](https://discourse.rom-rb.org/u/joelvh)\
**Post date:** [April 13, 2018, 9:49pm UTC](https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228/4 "2018-04-13T21:49:02Z")

</div>

@solnic I found today that `relation.command(:delete, result: nil).call` also returns an array as is expected based on the source code. For some reason, there is a behavioral difference between specifying `nil` and completely omitting the option altogether.

---

<div class="post-metadata">

**Author:** ![codeslinger](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@codeslinger](https://discourse.rom-rb.org/u/codeslinger)\
**Post date:** [September 13, 2022, 7:51pm UTC](https://discourse.rom-rb.org/t/delete-command-on-relation-should-return-all-deleted-entities/228/6 "2022-09-13T19:51:20Z")

</div>

This is helpful! When delete is returning entities is it possible to have them return a custom representation other than ROM:Struct or plain hash?
