Huxelpux
When and how is the violation_message for a relationship used?
I want to show a localized error message when a postgres database constraint for a relationship is violated (especially, during the destroy action of a parent record that still has child records that belong to it).
The documentation for the violation_message suggests that it shall be used for that purpose. It is “A message to show if there is a conflict with this relationship in the database on destroy.”
However, if I specify a violation_message for the belongs_to relationship, upon trying to destroy the record I only get an InvalidAttribute error on field :id with the standard message “would leave records behind”. Having an inverse has_many relationship with a violation_message does not change this, either.
So how can I specify a relationship-specific, localized violation_message (using gettext) that is then used in the error (or elsewhere)? Or are error messages not intended to be localized at all? How to specify and use relationship-specific, localized error messages for an application, then?
Marked As Solved
zachdaniel
Right, so it makes perfect sense to construct error messages internally that allow you to uniquely identify errors, but the actual localization of that would happen at the edges.
With that said, adding more information like the resource, relationship etc. to errors would only be a positive thing. Something we have to incrementally improve.
Also Liked
Huxelpux
Last Post!
Huxelpux
Popular in Questions
Other popular topics
Latest Ash Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









