Hi, I’m confused. If that’s the case why in the documentation example (below), new_changeset.params returns {title: "Foo"} instead of {title: "Hello"} ? Only the :body field should have been added in the returned changeset.
cast/3's signature is cast(data, params, allowed). In this case new_changeset.params is the second argument passed to cast/3. Maybe new_changeset.changes is what you’re looking for?
I had the exact same confusion on this example. I suggest breaking it up into two examples, one that starts with a struct and behaves the way https://elixirforum.com/users/aseity and I thought it would (with a result of %{“title” => “Hello”, “body” => “Bar”})
And then another that clarifies that you can preset allowed fields by starting with a changeset that already allows it.
[replying in the thread, I hope]
I had the exact same confusion on this example. I suggest breaking it up into two examples, one that starts with a struct and behaves the way https://elixirforum.com/users/aseity and I thought it would (with a result of %{“title” => “Hello”, “body” => “Bar”})
And then another that clarifies that you can preset allowed fields by starting with a changeset that already allows it.
I had the same confusion as @JohnB with this example. I did not realize that “allowed” field names were accumulated inside the changeset until reading this thread.