Hi all,
Why Repo.insert and Repo.insert_all act differently regarding autogenerated fields like id, inserted_at or updated_at?
When I saw insert_all, my first guess was: it does the same thing that insert does, but for multiples items. It turned out that it actually doesn’t do the same thing. I DO agree that we must have functions that are meant to be closer to the datastore, but maybe they should be named differently. e.g., insert_entries, insert_raw or whatever name we can find that explicitly and undoubtedly states their behaviour. Does it make sense?
Thanks!
-marlus
--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAJvhf-%3DUj8X1ZQec3x9Lv8ZLyv35kWonj750W0x%2BTw3KjgQHAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAGnRm4LSwOKsbnTC7oGexg4%3Dhbg37d_BP4JaSbZALm1a_OxB7Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAJvhf-nPAn_yMrsZ%2Bb%2B7b8-%3D3zmtLkmdhZXazMxkxSc%2BoKZEyA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/CAGnRm4KDGRskxBSQz_SY%3D7TZZY6e-D%2BNXckgtXuiu_cLTFhZfQ%40mail.gmail.com.
Hi Chris and José.
I don’t know if bulk_* will solve it. The problem is not the _all per se. The problem is that insert implicitly does some other things. One example is setting inserted_at and updated_at. That means I can do:
Repo.insert(%Post{title: "foo"})
but I can’t do:
Repo.insert_all(Post, [%{title: "foo1"}, %{title: "foo2"}]
With insert, the Repo will magically set inserted_at and updated_at. I think that would be OK as long the other similar functions, like insert_all did the same. But it doesn’t. If we try the second code, It will raise: ERROR (not_null_violation): null value in column “inserted_at” violates not-null constraint.
I’m pretty sure there must be some technical reason for update_all and insert_all to act like this. My only concern is that, in the near future, we may end up with an Repo API that is not intuitive anymore, and for each function that manipulates data we’ll need to ask: does this function set those fields or not, does it call that callback or not?
As far as I can see we may end up with two sets of functions: one set closer to the model and another set closer to the datastore.That might be a sign that maybe the problem is not even the functions names, but the responsibilities of the Repo itself. Should the Repo really have those two sets of functions together? If so, we probably want to, at least, “separate” them using some kind of pre/postfix. I know that _entries might not be the best name for it but at least it does NOT lead to the same kind of ambiguity. In this case there’s only one rule: if you see _entry or _entries, that means you’re close to the datastore, consequently, don't expect any implicit behaviour.
Anyway, I’m really excited about about v2.0.
Thanks again.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/4CA4D87E-15F5-4D86-9EF0-5C9893BEA444%40chrismcg.com.
--
You received this message because you are subscribed to the Google Groups "elixir-ecto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-ecto...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/a43422d0-0344-42e4-98b4-010bf32df5c8%40googlegroups.com.