defmodule MyProject.Post do
schema "..." do
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:title])
|> valdate_required([:title])
|> after_changes(&insert_version/1)
end
def insert_version(changeset) do
Version.changeset(%Version{}, version_params(changeset.data, changeset.action))
|> Repo.insert
|> case do
{:ok, _} -> changeset
{:error, cs} -> add_error(changeset, ....)
end
end
--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-ecto/7733ee23-ee2f-42f7-8e61-ce697e5e6db6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think the whatwasit design is a good example to illustrate the issue. To recap, my first attempt was to override Repo.update/delete. You pointed me to prepare_changes which I used (with side effects). And finally, in your comment above, you indicate that prepare_changes is not meant to handle side effects. :)
I guess my first question is if my expectation of being able to insert side effect based behaviour into an existing project with minimal changes is a correct one.
To support this, the user must modify each of their controllers' create/update/delete actions to call a <action>_with_insert/2 api on their Repo. Whereas the previous design required adding a use and 1 pipe to the changeset.
I believe this is a valid issue/concern, I just do not agree with the proposed solution so far. Let's keep the discussion alive.
If you are introducing this new API, then does the user need to call a function in their changeset in the first place?
--
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/b2faac43-a40a-4645-be67-18c8a8ae91d3%40googlegroups.com.
Composibility a pretty significant concern. This is where Plug adds significant value for web requests. I'm going to try prototyping some ideas.
--
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/c8407a5f-55e0-4994-89fa-0c6970f6b946%40googlegroups.com.