3 ms·
With put_assoc, at least for me, I expected it to work the same way when creating a record vs editing a record, but that isn't the case. While put_assoc is addi
by dqv 6y ago
With put_assoc, at least for me, I expected it to work the same way when creating a record vs editing a record, but that isn't the case. While put_assoc is additive when you are first creating the record, the same is not true when modifying a record. You have to provide all the original data in addition to the new record when modifying it.
Comments for that reason aren't a good use case for put_assoc, because generally you add a comment one at a time. It makes more sense to just create a new comment with the associated post ID.
Also the string keys in structs weirded me out - I don't think that works in Elixir.
- eyelidlessness 6y agoBased on your description, it sounds like it does behave the same way on create and update. In every case, you have to supply the whole dataset for the relations. Not being familiar with Ecto or Elixir (and only moderately familiar with Erlang), I would expect anything named `put` to be a full replacement. That's what I associate with the same verb in HTTP semantics, as well as in general FP semantics. It seems like a welcome place for an abstraction like `cons`, but I think even that may get into impedance mismatch territory...