Eiji
[SOLVED] When Ecto.Changeset action is set?
When I’m creating Post insert changeset from iex:
new_post = %MyProject.Post{}
changeset = Ecto.Changeset.cast(new_post, %{body: "Body", title: "Title"}, [:title, :body])
#Ecto.Changeset<action: nil, changes: %{body: "Body", title: "Title"},
errors: [], data: #First.Post<>, valid?: true>
When I’m creating Post update changeset from iex:
post = MyProject.Repo.get(MyProject.Post, 5)
changeset = Ecto.Changeset.cast(post, %{body: "Body", title: "Title"}, [:title, :body])
#Ecto.Changeset<action: nil, changes: %{body: "Body", title: "Title"},
errors: [], data: #First.Post<>, valid?: true>
It always returns action: nil. When Ecto.Changeset action is set?
Marked As Solved
michalmuskala
When you pass the changeset to one of the Repo functions.
2
Also Liked
michalmuskala
I’m not sure that’s the right approach - why not create multiple changeset functions?
def create_changeset(schema, params) do
schema
|> common_changeset(params)
|> create_specific_operations
end
def update_changeset(schema, params) do
schema
|> common_changeset(params)
|> update_specific_operations
end
def common_changeset(schema, params) do
# ...
end
4
Eiji
You mean: delete(!), insert(!) and update(!), right?
I want to have it set in changeset model function (before affect database) and perform some actions (in cond do statement).
Is it possible? Or I need set it manually? Or maybe one more parameter in changeset function for cond do statement is better solution?
1
Popular in Questions
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Hi,
is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Other popular topics
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Got a question about when to concat vs. prepending items to list then reversing to achieve appending.
So i know lists boil down to [1 | ...
New
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!)
This post collects co...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









