# ROM upsert and schema validation

**URL:** <https://discourse.rom-rb.org/t/rom-upsert-and-schema-validation/605>\
**Category:** Issues\
**Created:** [May 21, 2023, 10:08pm UTC](https://discourse.rom-rb.org/t/rom-upsert-and-schema-validation/605 "2023-05-21T22:08:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ridget](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ridget/32/296_2.png) [@ridget](https://discourse.rom-rb.org/u/ridget)\
**Post date:** [May 21, 2023, 10:08pm UTC](https://discourse.rom-rb.org/t/rom-upsert-and-schema-validation/605/1 "2023-05-21T22:08:21Z")

</div>

Hi friends - wondering if I can get some 2c - relative noob to ROM

I was attempting to use `relation.upsert` with options but found that it wasn’t validating via the schema - which appears to be expected behaviour.

Instead as I was trying to get the upsert command working as I wanted/needed it to, and ended up reaching for a new custom command class extending from the `ROM::SQL::Postgres::Commands::Upsert` like so

```auto
  class UserUpsert < ROM::SQL::Postgres::Commands::Upsert
      relation :users
      register_as :upsert
      conflict_target :name
      update_statement title: Sequel[:excluded][:title], email: Sequel[:excluded][:email]
    end

    class UserRepository < Repository[:users]
      commands :upsert
    end

```

Is there an easier/more idiomatic/more efficient way to do this that I’m just not seeing? Or is this fine the way it is?

Note the update\_statement just uses the values being passed to it for those columns as the things to update with - unclear if there’s a better approach here, too

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/alassek/32/260_2.png) [@alassek](https://discourse.rom-rb.org/u/alassek)\
**Post date:** [May 22, 2023, 6:07pm UTC](https://discourse.rom-rb.org/t/rom-upsert-and-schema-validation/605/2 "2023-05-22T18:07:33Z")

</div>

This is probably the best solution that I’m aware of.

---

<div class="post-metadata">

**Author:** ![ridget](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/ridget/32/296_2.png) [@ridget](https://discourse.rom-rb.org/u/ridget)\
**Post date:** [May 22, 2023, 10:45pm UTC](https://discourse.rom-rb.org/t/rom-upsert-and-schema-validation/605/3 "2023-05-22T22:45:11Z")

</div>

Thanks kindly - wasnt sure if I was over-thinking it
