There appears to be several ways to handle transactions, but I'd like to really narrow in on a clean way to handle logging entries from within a transaction. Let's use a simple example such as a Post. So when I create a Post from a Phoenix LiveView, I'd like to call a wrapper action for it such as
actions do create :create_with_log do argument(:title, :string) Post.create!(title: ^arg(:title)) Post.log!(:create, "Created a new post.") end end
actions do create :create_with_log do argument(:title, :string) Post.create!(title: ^arg(:title)) Post.log!(:create, "Created a new post.") end end
Of course this is simplified not fully working. But it's not clear to me if this is the idiomatic way to handle something like this. I can use Flows or even wrap an Ecto.Multi call, but seems that actions are already transactional and I should be able to re-use the mechanism for this.
The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.