# Changeset \`:create\` command with aliased PK doesn't seem to map back to database column

**URL:** <https://discourse.rom-rb.org/t/changeset-create-command-with-aliased-pk-doesnt-seem-to-map-back-to-database-column/225>\
**Category:** Issues\
**Created:** [April 8, 2018, 8:41pm UTC](https://discourse.rom-rb.org/t/changeset-create-command-with-aliased-pk-doesnt-seem-to-map-back-to-database-column/225 "2018-04-08T20:41:06Z")\
**Posts on this page:** 3\
**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 8, 2018, 8:41pm UTC](https://discourse.rom-rb.org/t/changeset-create-command-with-aliased-pk-doesnt-seem-to-map-back-to-database-column/225/1 "2018-04-08T20:41:06Z")

</div>

I’ve created a relation where the `id` is aliased to `event_id`. When I try to create new records by committing the changeset with data that has an `event_id` value pre-populated, the value is not persisted to the `id` column (get a SQL null violation exception).

```ruby
      class Events < ::ROM::Relation[:sql]
        schema(:event_store_events, as: :events, infer: true) do
          attribute :id, ::ROM::Types::String.meta(alias: :event_id)

          primary_key :id
        end
      end

```

Is it not the expectation that the changeset commands will write to the original attribute name (SQL column)?

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 9, 2018, 11:59am UTC](https://discourse.rom-rb.org/t/changeset-create-command-with-aliased-pk-doesnt-seem-to-map-back-to-database-column/225/2 "2018-04-09T11:59:05Z")

</div>

Hey Joel!

There’s no auto-mapping in the changesets, so at the moment you’d have to define mapping manually. For simple attr-aliasing we could introduce a changeset plugin that could infer the mapping from schemas. Changeset plugins, in general, are scheduled for rom 5.0.0.

---

<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:16am UTC](https://discourse.rom-rb.org/t/changeset-create-command-with-aliased-pk-doesnt-seem-to-map-back-to-database-column/225/3 "2018-04-13T00:16:44Z")

</div>

Hi @solnic! Thanks for the clarification. I would have assumed that the schema would manage the mapping for the changeset.

I have made many observations about the changeset functionality and look forward to seeing where it goes to improve things.
