#elixir-lang

/

      • renatomo_ has quit
      • Uniaika has quit
      • maxbeizer has quit
      • trxtr joined the channel
      • hassox has quit
      • josevalim has quit
      • bitwalker has quit
      • meekrab joined the channel
      • greengriminal has quit
      • jhny has quit
      • dfinninger has quit
      • datanoise joined the channel
      • dnorris joined the channel
      • davidw has quit
      • micmus has quit
      • datanoise has quit
      • torstein joined the channel
      • gandaro has quit
      • sotojuan has quit
      • Gringill joined the channel
      • strburst joined the channel
      • torstein has quit
      • nd___ joined the channel
      • robramsaynz joined the channel
      • cdg has quit
      • hewsut has quit
      • cdg joined the channel
      • hassox joined the channel
      • pezra_ has quit
      • wless1 has quit
      • wless1 joined the channel
      • hewsut joined the channel
      • cdg has quit
      • sudomarize has quit
      • wojtekmach joined the channel
      • datanoise joined the channel
      • stephen_m has quit
      • strburst has quit
      • strburst joined the channel
      • renatomoya joined the channel
      • devbug has quit
      • hassox has quit
      • renatomoya has quit
      • sevenseacat joined the channel
      • CharlesO has quit
      • renatomoya joined the channel
      • dnorris has quit
      • wless1 has quit
      • edgurgel joined the channel
      • hassox joined the channel
      • renatomoya has quit
      • renatomoya joined the channel
      • hipertracker
        I can’t solve the problem with inserting a new record using Ecto (Phoenix). It does not make any sense. One syntax works, another doesn not. https://gist.github.com/hipertracker/483d7d89e6...
      • lyuha has quit
      • davidw joined the channel
      • kblake has quit
      • wojtekmach
        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}
      • but that does not:
      • language = Repo.one(Language)
      • params = %{code: "bg5", name: "BG5", language_id: language.id, info: "some", year: "1975"}
      • changeset = Bible.changeset(%Bible{}, params)
      • Repo.insert!(changeset)
      • ** (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
      • ericmj
        hipertracker: can you show the updated code?
      • datanoise has quit
      • hipertracker
        ericmj: what code?
      • ericmj
        of the code in the gist
      • josh-k joined the channel
      • dnorris joined the channel
      • josh-k_ joined the channel
      • drewolson has quit
      • hipertracker
        I have a second gist. The problem is with changeset and my foreign key. It’s always null in SQL https://gist.github.com/hipertracker/4044faa960...
      • ericmj
        hipertracker: can you show the code you changed?
      • hipertracker
        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}
      • %{available: false, code: "bg5", info: "some", language_id: 49, name: "BG5",
      • hezhiqiang joined the channel
      • CharlesO has quit
      • ericmj
        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
      • ericmj
        okay, then can you show the code you changed?
      • hipertracker
        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?
      • pezra joined the channel
      • hewsut has quit
      • trxtr has quit