# Memory relation Delete command fails because of mismatched types when deleting tuples from dataset

**URL:** <https://discourse.rom-rb.org/t/memory-relation-delete-command-fails-because-of-mismatched-types-when-deleting-tuples-from-dataset/249>\
**Category:** Issues\
**Created:** [April 26, 2018, 10:44pm UTC](https://discourse.rom-rb.org/t/memory-relation-delete-command-fails-because-of-mismatched-types-when-deleting-tuples-from-dataset/249 "2018-04-26T22:44:07Z")\
**Posts on this page:** 4\
**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 26, 2018, 10:44pm UTC](https://discourse.rom-rb.org/t/memory-relation-delete-command-fails-because-of-mismatched-types-when-deleting-tuples-from-dataset/249/1 "2018-04-26T22:44:07Z")

</div>

I’m implementing some ROM relations with the `:memory` adapter and have a failing test that seems like it should work. Calling the `delete` command doesn’t seem to delete tuples. Looking at the ROM tests for Memory-related commands, it seems the delete command is not in the test suite.

Could it be related to the relation criteria or how the storage is configured?

The tests are in [this `ruby_event_store-rom` gem](https://github.com/RailsEventStore/rails_event_store/tree/feature/rom_memory_adapter/ruby_event_store-rom). This is the command that will show 4 failing tests:

`DATABASE_URL=memory:// ROM_ADAPTER=Memory make test`

This project is to allow swapping multiple backing stores via a relation interface, where Memory is a drop-in replacement for SQL.

Any insights are welcome!

Thanks.

---

<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 27, 2018, 8:46am UTC](https://discourse.rom-rb.org/t/memory-relation-delete-command-fails-because-of-mismatched-types-when-deleting-tuples-from-dataset/249/2 "2018-04-27T08:46:12Z")

</div>

Please report an issue if you can confirm that it’s broken. FWIW I would love to make memory adapter truly first-class, as it can become an abstract API for other adapters, like rom-yaml/csv/git etc.

---

<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 27, 2018, 1:36pm UTC](https://discourse.rom-rb.org/t/memory-relation-delete-command-fails-because-of-mismatched-types-when-deleting-tuples-from-dataset/249/3 "2018-04-27T13:36:03Z")

</div>

OK. That was my question, whether I should post an issue rather than a Discourse post. I’ll fork ROM and see if I can create some failing tests and PR that.

---

<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 27, 2018, 5:35pm UTC](https://discourse.rom-rb.org/t/memory-relation-delete-command-fails-because-of-mismatched-types-when-deleting-tuples-from-dataset/249/4 "2018-04-27T17:35:40Z")

</div>

@solnic I discovered that the stored tuple is a `Hash` in memory, but the tuple being deleted is a `Struct`…

The delete command is being called on a relation, so I understand that it would return a struct and run the command.

```ruby
relation.by_stream(stream_name).command(:delete).call

```

The solution was to call:

```ruby
relation.by_stream(stream_name).map_with(auto_struct: false).command(:delete).call

```

The reason the datastore uses hashes is because of the recommendation to use hashes when persisting. However, with this Memory datastore, it seems there needs to be a way to convert structs to hashes for comparison only.

The issue with the solution above is that the tuples returned from the delete command are now `Hash`es instead of `Struct`s.

While this solves the comparison, it technically breaks the typing of the result set (even if we are discarding it in our use case).

Is this approach in the right direction, ROM-wise?

P.S. I like changesets… is there a feature of changesets that can help address this issue of proper type comparison and then properly typed result set?
