hipertracker: you mean Repo.insert!(%Bible{...}) works, but Repo.insert(changeset) doesn't? I think the first writes directly to adapter, whereas the 2nd runs validations; you're not passing in `year` which is a required field into your changeset
enitiz has quit
AustinMatherne joined the channel
davidw has quit
hipertracker
wojtekmach: not exactly. this works Repo.insert! %Bible{code: "bg3", name: "BG3", language_id: language.id}
** (Postgrex.Error) ERROR (not_null_violation): null value in column "language_id" violates not-null constraint
I am loosing my language_id value for unknown reason
wojtekmach
hipertracker: double-check if it's in @required_ or @optional_fields in your changeset
jeffweiss has quit
hipertracker
but, I added those required fields. first syntax works and assign null for them. the second does not work at all because my language_id is alway null. but changeset has params: %{"code" => "bg5", "info" => "some", "language_id" => 49,
"name" => "BG5", "year" => "1975"}
so, it’s all there
and it’s gone after insert!
zd_ is now known as zd
wojtekmach
I mentioned it, because I didn't see langauage_id in required/optional fields in your gist. weird, not sure what's wrong
Repo.insert! Map.merge(%Bible{}, params) works perfect, but Repo.insert!(Bible.changeset(%Bible{}, params)) does not work
ericmj
02:10 <hipertracker> but, I added those required fields.
^ you didnt add those fields in the gist above
hipertracker
It is in the second gist
ericmj
no, the changeset code
oh, you misunderstand
hipertracker
it uses :code, :name, :year, :sort, :info, :available, :preselected
ericmj
all parameters you want to change should be in required or optional fields
otherwise ecto ignores them
sevenseacat
that's bitten me more than once
dignifiedquire has quit
hipertracker
But it does not ignore if I use Repo.insert!(Map.merge(%Bible{}, params)) it only nulify my language_id constrain when I use that syntax Repo.insert!(Bible.changeset(%Bible{}, params))
hewsut has quit
why the first works, and the second does not?
ericmj
it always insersts all fields
hewsut joined the channel
hipertracker
ok, but in the second case it destroy my language_id value. and I have not null there, so it can;t be null
wojtekmach
hipertracker: I think what Eric is asking is for you to update your original gist (which includes your schema/changeset definiton and how you're using it) - this way it should be easier to try to help out
hipertracker
wojtekmach: but what should I change? I can see nothing to improve there.
strburst_ joined the channel
mattbradley joined the channel
ericmj
you have to lists of optional and required fields
add the fields you want include in your changeset to either of those lists
damrkul has quit
damrkul joined the channel
mackenza joined the channel
Kham joined the channel
torstein joined the channel
CharlesO joined the channel
strburst has quit
hipertracker
ericmj: no, I use them. have a look at the second gist. it uses the same models. this time i added all fields iex(3)> params = %{code: "bg5", name: "BG5", language_id: language.id, info: "some", year: "1975", sort: 0, available: false, preselected: true}
search your code for @required_fields and @optional_fields
add the fields you want included when store things in the database to one of those lists
hipertracker
ericmj: I do not have any more code. I included all required fields.
wojtekmach
hipertracker: you need to update this line if you haven't already: https://gist.github.com/hipertracker/483d7d89e6...; this is what we were telling you about. if you already updated it and are still getting errors, then it's weird
ericmj
literally search your code for “@required_fields” and add language_id on that line
not sure how i can explain it any other way
hipertracker
I am still getting the error
I do not have any more code. just that models and iex
I did not change anything in the model definition. All what is diffent is just iex commands
ericmj
that’s @required_fields
Kham has quit
you do not have language_id on that line
add it to that line
mackenza has quit
hewsut has quit
hewsut joined the channel
torstein has quit
hipertracker
ericmj: added
hmm, now works. so changeset is so sensitive?
marr has quit
ericmj
yes, otherwise your users can insert whatever they want to the database
tuelz joined the channel
someone can add a parameter admin=true when updating your user profile
hipertracker
because Repo.insert!(Map.merge(%Bible{}, params)) works even if required fields has no that field. should I avoid such syntax and use always changeset instead?