# Delete Cascade to include associated records?

**URL:** <https://discourse.rom-rb.org/t/delete-cascade-to-include-associated-records/556>\
**Category:** Issues\
**Created:** [September 13, 2022, 8:21pm UTC](https://discourse.rom-rb.org/t/delete-cascade-to-include-associated-records/556 "2022-09-13T20:21:53Z")\
**Posts on this page:** 3\
**Page:** 1

<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, 8:21pm UTC](https://discourse.rom-rb.org/t/delete-cascade-to-include-associated-records/556/1 "2022-09-13T20:21:53Z")

</div>

Is it possible to delete records that have an association (foreign key) to schedule\_elements in a single call? Do I just combine the associated relation?

```auto
schedule_elements.where(conditions).command(:delete, result: :many).call

```

P.S. Can “command(:delete, result: :many)” just return ids?

Thanks!

---

<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 14, 2022, 2:14pm UTC](https://discourse.rom-rb.org/t/delete-cascade-to-include-associated-records/556/2 "2022-09-14T14:14:02Z")

</div>

I may have answered my own question using sequel, however, are there any tricks in ROM to do this?

```auto
Foreign Key Options

:on_delete

    Specify the behavior of this foreign key column when the row with the primary key it references is deleted, can be :restrict, :cascade, :set_null, or :set_default. You can also use a string, which is used literally.

```

---

<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:** [September 16, 2022, 8:57am UTC](https://discourse.rom-rb.org/t/delete-cascade-to-include-associated-records/556/3 "2022-09-16T08:57:14Z")

</div>

It’s best to define an FK constraint at the database level with `on_delete: :cascade`
