thousandsofthem
Add_error for embedded changeset
How exactly i can add an error into nested/embedded changeset? Don’t think add_error can do this.
Context: regular changeset validation already happened and i’m doing some external check
e.g.
...
defmodule Thing do
schema "things" do
embeds_one :config, ThingConfig, on_replace: :update
end
end
...
defmodule ThingConfig do
@primary_key false
embedded_schema do
field :param, :string
end
end
# ??
ch1 = Ecto.Changeset.add_error(ch.changes.config, :param, "error")
# ??????
Ecto.Changeset.put_embed(ch, :config, ch1)
on insert it works, on update - error:
Since you have set
:on_replaceto:update, you are only allowed
to update the existing entry by giving updated fields as a map or
keyword list or set it to nil.
Marked As Solved
LostKobrakai
update_in(ch.changes.config, fn changeset ->
Ecto.Changeset.add_error(changeset, :param, "error")
end)
Just be aware that this won’t make the parent become valid?: false.
3
Popular in Questions
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
Student & New to elixir. Nice language.
I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
I would like to know what is the best IDE for elixir development?
New
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
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,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
can someone please explain to me how Enum.reduce works with maps
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
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
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 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
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including.
What is Phoenix LiveV...
New







