# \#changeset

**URL:** https://forum.elixirforum.com/tag/changeset/3265.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [Using Phoenix.HTML.Form for M2M-Relations using a Multiple Select Input in a LiveView](https://forum.elixirforum.com/t/using-phoenix-html-form-for-m2m-relations-using-a-multiple-select-input-in-a-liveview/71123)

<div class="topic-metadata">

**Author:** [@maqnius](https://forum.elixirforum.com/u/maqnius)\
**Replies:** 14\
**Last updated:** [June 15, 2025, 6:54pm UTC](https://forum.elixirforum.com/t/using-phoenix-html-form-for-m2m-relations-using-a-multiple-select-input-in-a-liveview/71123 "2025-06-15T18:54:49Z")

</div>

Hey there :slight\_smile: I was trying to adapt the Contexts Article using the Form Struct and to\_form. I ended up having problems to render the input \<.input field={@form\[:categories\]} type="select" …

---

## [Where to validate scope values in phoenix v1.8.0](https://forum.elixirforum.com/t/where-to-validate-scope-values-in-phoenix-v1-8-0/70868)

<div class="topic-metadata">

**Author:** [@Liam\_or](https://forum.elixirforum.com/u/Liam_or)\
**Replies:** 0\
**Last updated:** [May 14, 2025, 10:43am UTC](https://forum.elixirforum.com/t/where-to-validate-scope-values-in-phoenix-v1-8-0/70868 "2025-05-14T10:43:57Z")

</div>

Hello everyone :slight\_smile: I’m wondering what the accepted approach is for validating values in the new Scope struct. When I run phx.gen.context , I see that scope is passed into the changeset. Should validations liv…

---

## [\`after\_action\` hook does not trigger with atomic changes](https://forum.elixirforum.com/t/after-action-hook-does-not-trigger-with-atomic-changes/70822)

<div class="topic-metadata">

**Author:** [@kamaroly](https://forum.elixirforum.com/u/kamaroly)\
**Replies:** 4\
**Last updated:** [May 12, 2025, 6:46pm UTC](https://forum.elixirforum.com/t/after-action-hook-does-not-trigger-with-atomic-changes/70822 "2025-05-12T18:46:30Z")

</div>

I have observed that after\_action hook silently gets ignored when a change is atomic but when I set require\_atomic? to false it triggers. I could not find anything in the docs that explains the rationale behind this be…

---

## [Changeset is not validating data](https://forum.elixirforum.com/t/changeset-is-not-validating-data/70354)

<div class="topic-metadata">

**Author:** [@Fl4m3Ph03n1x](https://forum.elixirforum.com/u/Fl4m3Ph03n1x)\
**Replies:** 6\
**Last updated:** [April 8, 2025, 6:03pm UTC](https://forum.elixirforum.com/t/changeset-is-not-validating-data/70354 "2025-04-08T18:03:22Z")

</div>

Background I am trying to create a schema with some basic validations. However, when I spin up my app, it looks like the validations are not running. Code This is the schema for a reservation. defmodule MyApp.Reserve d…

---

## [\<.inputs\_for\> with has many relations, unable to access associated relations](https://forum.elixirforum.com/t/inputs-for-with-has-many-relations-unable-to-access-associated-relations/64935)

<div class="topic-metadata">

**Author:** [@CessK](https://forum.elixirforum.com/u/CessK)\
**Replies:** 2\
**Last updated:** [July 16, 2024, 10:14pm UTC](https://forum.elixirforum.com/t/inputs-for-with-has-many-relations-unable-to-access-associated-relations/64935 "2024-07-16T22:14:33Z")

</div>

Hello Everyone, I am still quite new to the Phoenix framework and I am struggling with the has\_many relationship using ecto and how to render those has\_may to an \<.simple\_form\> component. I am trying to setup a User ro…

---

## [How to add a global error to an Ecto changeset? (Not specific to a single field)](https://forum.elixirforum.com/t/how-to-add-a-global-error-to-an-ecto-changeset-not-specific-to-a-single-field/64585)

<div class="topic-metadata">

**Author:** [@arcanemachine](https://forum.elixirforum.com/u/arcanemachine)\
**Replies:** 4\
**Last updated:** [June 28, 2024, 9:10pm UTC](https://forum.elixirforum.com/t/how-to-add-a-global-error-to-an-ecto-changeset-not-specific-to-a-single-field/64585 "2024-06-28T21:10:16Z")

</div>

In Django, there is the concept of “non\_field\_errors”, which exists when a form field has an error that is not specific to any model field. I am just wondering if there is a similar convention in Ecto. I have an error t…

---

## [Changset.add\_error not working inside \`before\_action\` block?](https://forum.elixirforum.com/t/changset-add-error-not-working-inside-before-action-block/63028)

<div class="topic-metadata">

**Author:** [@jason.o](https://forum.elixirforum.com/u/jason.o)\
**Replies:** 8\
**Last updated:** [April 21, 2024, 3:55pm UTC](https://forum.elixirforum.com/t/changset-add-error-not-working-inside-before-action-block/63028 "2024-04-21T15:55:02Z")

</div>

This code is intended to validate a user typed DELETE before deleting their account, but it doesn’t work because add\_error isn’t adding the error nor making the changeset valid?: false. Perhaps the issue might be that it…

---

## [How to use embeds\_many with schemaless changeset?](https://forum.elixirforum.com/t/how-to-use-embeds-many-with-schemaless-changeset/61891)

<div class="topic-metadata">

**Author:** [@mogadget](https://forum.elixirforum.com/u/mogadget)\
**Replies:** 0\
**Last updated:** [February 26, 2024, 3:08am UTC](https://forum.elixirforum.com/t/how-to-use-embeds-many-with-schemaless-changeset/61891 "2024-02-26T03:08:37Z")

</div>

I have this schemaless changeset fields data = %{} types = %{name: :string, email: :string, age: :integer} params = %{name: "Callum", email: "callum@example.com", age: 27} changeset = {data, types} |\> Ecto.Changese…

---

## [What is the correct way to re-execute validation on a Ecto Schema?](https://forum.elixirforum.com/t/what-is-the-correct-way-to-re-execute-validation-on-a-ecto-schema/61634)

<div class="topic-metadata">

**Author:** [@lorenzomar](https://forum.elixirforum.com/u/lorenzomar)\
**Replies:** 1\
**Last updated:** [February 13, 2024, 10:04am UTC](https://forum.elixirforum.com/t/what-is-the-correct-way-to-re-execute-validation-on-a-ecto-schema/61634 "2024-02-13T10:04:33Z")

</div>

Hi there! I’m in the situation where I’m receiving a struct which is also an Ecto Schema (wich embedded\_one/many other schemas). To be more precise it is a Commanded command. Sometimes I may not be in control of how th…

---

## [What is the difference between \`Ash.Changeset.for\_action\` and \`Ash.Changeset.for\_\*\`?](https://forum.elixirforum.com/t/what-is-the-difference-between-ash-changeset-for-action-and-ash-changeset-for/59007)

<div class="topic-metadata">

**Author:** [@Pistrie](https://forum.elixirforum.com/u/Pistrie)\
**Replies:** 3\
**Last updated:** [October 16, 2023, 9:34am UTC](https://forum.elixirforum.com/t/what-is-the-difference-between-ash-changeset-for-action-and-ash-changeset-for/59007 "2023-10-16T09:34:17Z")

</div>

The different for\_\* actions require a specific action atom (i.e. |\> for\_create(:create, opts) ), so what’s the point of these explicit functions?

---

## [Preload associations with cast\_embed](https://forum.elixirforum.com/t/preload-associations-with-cast-embed/58046)

<div class="topic-metadata">

**Author:** [@agonzalezro](https://forum.elixirforum.com/u/agonzalezro)\
**Replies:** 6\
**Last updated:** [September 9, 2023, 8:18pm UTC](https://forum.elixirforum.com/t/preload-associations-with-cast-embed/58046 "2023-09-09T20:18:37Z")

</div>

Hi :wave: I had this piece of (working) code: items = products |\> Enum.map(fn product -\> params = %{product\_id: product.id} Snapshot.new\_item\_changeset( %Snapshot.Item{ …

---

## [Changeset struct undefined in Phoenix 1.7](https://forum.elixirforum.com/t/changeset-struct-undefined-in-phoenix-1-7/56761)

<div class="topic-metadata">

**Author:** [@acke](https://forum.elixirforum.com/u/acke)\
**Replies:** 3\
**Last updated:** [June 29, 2023, 4:40pm UTC](https://forum.elixirforum.com/t/changeset-struct-undefined-in-phoenix-1-7/56761 "2023-06-29T16:40:35Z")

</div>

Changeset struct undefined Hello everbody. I’m just getting started learning Phoenix and I’m trying to create a basic Github clone as a learning project. I got stuck on an issue regarding the changeset struct, and couldn…

---

## [Found a bug in Ecto changeset unique\_constraint function](https://forum.elixirforum.com/t/found-a-bug-in-ecto-changeset-unique-constraint-function/56336)

<div class="topic-metadata">

**Author:** [@prkhrkat](https://forum.elixirforum.com/u/prkhrkat)\
**Replies:** 3\
**Last updated:** [June 6, 2023, 7:11pm UTC](https://forum.elixirforum.com/t/found-a-bug-in-ecto-changeset-unique-constraint-function/56336 "2023-06-06T19:11:44Z")

</div>

I have a table in which I have put unique constraints on the combination of two fields. I had also defined this in changeset. def changeset(asset, attrs) do asset |\> cast(attrs, @create\_attrs) |\> validate\_re…

---

## [Errors in Liveview: Parse error ... expected attribute name](https://forum.elixirforum.com/t/errors-in-liveview-parse-error-expected-attribute-name/55423)

<div class="topic-metadata">

**Author:** [@boiserunner](https://forum.elixirforum.com/u/boiserunner)\
**Replies:** 3\
**Last updated:** [April 21, 2023, 2:15pm UTC](https://forum.elixirforum.com/t/errors-in-liveview-parse-error-expected-attribute-name/55423 "2023-04-21T14:15:27Z")

</div>

I’m stumped. I have a LiveView form tied to a Changeset (rather than a schema) like so: ~H""" \<.form as={:form} for={@changeset} :let={f} phx-change="validate" phx-submit="save"\> \<.input field={f\[:email\]} /\> \</.…

---

## [How to set a limit for inputs\_for? / Frontend only pagination on a changeset form](https://forum.elixirforum.com/t/how-to-set-a-limit-for-inputs-for-frontend-only-pagination-on-a-changeset-form/54547)

<div class="topic-metadata">

**Author:** [@mattmartian](https://forum.elixirforum.com/u/mattmartian)\
**Replies:** 2\
**Last updated:** [March 14, 2023, 2:29pm UTC](https://forum.elixirforum.com/t/how-to-set-a-limit-for-inputs-for-frontend-only-pagination-on-a-changeset-form/54547 "2023-03-14T14:29:02Z")

</div>

Hi there! Within my form changeset there is a field that holds more than 700 records, I would paginate straight from the DB however I need all of them to be in memory, but only 5 to display on the screen. Can anybody he…

---

## [Put\_assoc can update column in case of the same pk?](https://forum.elixirforum.com/t/put-assoc-can-update-column-in-case-of-the-same-pk/53886)

<div class="topic-metadata">

**Author:** [@alexsysm](https://forum.elixirforum.com/u/alexsysm)\
**Replies:** 2\
**Last updated:** [February 14, 2023, 10:00am UTC](https://forum.elixirforum.com/t/put-assoc-can-update-column-in-case-of-the-same-pk/53886 "2023-02-14T10:00:12Z")

</div>

The associated data may be given in different formats: \* a map or a keyword list representing changes to be applied to the associated data. A map or keyword list can be given to update the associated data as long as…

---

## [How to handle unique constraint when using put\_assoc](https://forum.elixirforum.com/t/how-to-handle-unique-constraint-when-using-put-assoc/53884)

<div class="topic-metadata">

**Author:** [@enkr1](https://forum.elixirforum.com/u/enkr1)\
**Replies:** 2\
**Last updated:** [February 14, 2023, 6:11am UTC](https://forum.elixirforum.com/t/how-to-handle-unique-constraint-when-using-put-assoc/53884 "2023-02-14T06:11:02Z")

</div>

Hi community, I am doing a test case and I have an associative table with FKs user\_id and role\_id. When I tried to insert with the repeated FKs (1, 1) like: %User |\> User.creation\_changeset(%{ email: "unqiue@gmail.co…

---

## [How should I handle attrs validations?](https://forum.elixirforum.com/t/how-should-i-handle-attrs-validations/53523)

<div class="topic-metadata">

**Author:** [@MatijaL](https://forum.elixirforum.com/u/MatijaL)\
**Replies:** 0\
**Last updated:** [January 30, 2023, 12:28pm UTC](https://forum.elixirforum.com/t/how-should-i-handle-attrs-validations/53523 "2023-01-30T12:28:36Z")

</div>

Hello, I’m building a small app for learning purposes where I have users and those users can create projects. Projects can have different statuses and when the project status changes, embeded meta field is updated. Proj…

---

## [Changeset error parsing](https://forum.elixirforum.com/t/changeset-error-parsing/50858)

<div class="topic-metadata">

**Author:** [@hawkyre](https://forum.elixirforum.com/u/hawkyre)\
**Replies:** 2\
**Last updated:** [October 16, 2022, 8:27am UTC](https://forum.elixirforum.com/t/changeset-error-parsing/50858 "2022-10-16T08:27:58Z")

</div>

I want to create some kind of procedure to programmatically transform a changeset’s errors into my own error codes so that I can display them in the frontend. I’ve come up with the following: def create(%{} = course) d…

---

## [Need help creating a changeset function with multiple fields check both from database and changeset](https://forum.elixirforum.com/t/need-help-creating-a-changeset-function-with-multiple-fields-check-both-from-database-and-changeset/49936)

<div class="topic-metadata">

**Author:** [@MatijaL](https://forum.elixirforum.com/u/MatijaL)\
**Replies:** 2\
**Last updated:** [September 1, 2022, 7:21pm UTC](https://forum.elixirforum.com/t/need-help-creating-a-changeset-function-with-multiple-fields-check-both-from-database-and-changeset/49936 "2022-09-01T19:21:53Z")

</div>

Hi, I’m trying to create a function for the last couple of hours with no luck so I could really use your help. So, it’s a Phoenix app and I have a user profile form. There are several fields in that form like name, cit…

---

## [What's the difference between required: true on cast\_assoc and validate\_required?](https://forum.elixirforum.com/t/whats-the-difference-between-required-true-on-cast-assoc-and-validate-required/49230)

<div class="topic-metadata">

**Author:** [@elt547](https://forum.elixirforum.com/u/elt547)\
**Replies:** 2\
**Last updated:** [July 30, 2022, 8:05am UTC](https://forum.elixirforum.com/t/whats-the-difference-between-required-true-on-cast-assoc-and-validate-required/49230 "2022-07-30T08:05:25Z")

</div>

What’s the difference in behaviour of required between these uses? cast\_assoc(:author, required: true) # vs this validate\_required(:author\_id)

---

## [The fields of the inner form inputs\_for got reset when modifying other fields](https://forum.elixirforum.com/t/the-fields-of-the-inner-form-inputs-for-got-reset-when-modifying-other-fields/48411)

<div class="topic-metadata">

**Author:** [@enkr1](https://forum.elixirforum.com/u/enkr1)\
**Replies:** 4\
**Last updated:** [June 20, 2022, 7:45am UTC](https://forum.elixirforum.com/t/the-fields-of-the-inner-form-inputs-for-got-reset-when-modifying-other-fields/48411 "2022-06-20T07:45:25Z")

</div>

I have a map field which stores my mobile\_json and I used inputs\_for to display the embedded\_schema’s fields which looks like: \<%= inputs\_for f, :m\_json, fn mobile\_json -\> %\> \<div class="mobile-number-input-container"\> …
