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
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
I have a User schema with a :from_id field set to type :string:
defmodule TweetBot.Repo.Migrations.CreateUsers do
use Ecto.Migration
...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> someth...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
Other popular topics
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
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 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
I have a super simple question about elixir - how would I take a file like this
foo bar baz
and output a new file that enumerates th...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hey :wave:t3: Elixir community,
I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New







