New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repo.insert/2 Struct converted to Changeset #2197
Comments
The struct is converted to a Changeset using Ecto.Changeset.change/2, not
your own function, since that would be hard to do for the reasons
mentioned. Can you please send a PR that makes the docs clearer? Thank you.
--
*José Valim*
www.plataformatec.com.br
Skype: jv.ptec
Founder and Director of R&D
|
I think I understand the documentation now based on your feedback. iex(18)> Ecto.Changeset.change %User{email: "test@gmail.com"}
#Ecto.Changeset<action: nil, changes: %{}, errors: [],
data: #Try.Accounts.User<>, valid?: true> Example 1 iex(19)> User.changeset(%User{}, %{email: "test@gmail.com"})
#Ecto.Changeset<action: nil, changes: %{email: "test@gmail.com"},
errors: [name: {"can't be blank", [validation: :required]},
password: {"can't be blank", [validation: :required]}],
data: #Try.Accounts.User<>, valid?: false> Example 2 When I read this part of the documentation
I thought since my |
Yes, precisely.
|
Based on beam-community/ex_machina#111 Also see elixir-ecto/ecto#2197 Co-authored-by: Ana Pérez Ghiglia <aghiglia@manas.tech>
Environment
Current Version
Current behavior
Ecto.Repo.insert/2 states
When I fire up the console in my Phoenix 1.3 app my changeset fails (which is correct because of validation) but my struct passes and is inserted in the DB.
Here is the User Schema I'm using...
Expected behavior
I expected the struct to fail if the documentation is saying that the struct will be converted into a changeset.
In other documentation:
What's new in Ecto 2.1 PDF that Plataformatec provides as a download. It also has under a section called Less Changesets pg 38 and it states:
I did get some feedback on Slack in the Ecto Channel that its probably an error in documentation and the idea that a struct will be converted into a changeset automatically is unlikely because you may have multiple changesets for that schema and how would it know.
What am I doing wrong?
The text was updated successfully, but these errors were encountered: