nallwhy
What is the best practice for `Ash.can?/3`
Here’s the my example.
I’m working with structure where a Room has_one Contract, and I want to enforce that a contract can only be created when the room is unsold. However, when using Ash.can?({Contract, :create}, actor), I can’t access the parent room’s state. So, I thought it would be necessary to verify the policy through Ash.can?({Room, :contract}, actor). For this reason, I’ve adjusted the Room’s contract action to take :contract_params in a map. This adjustment has led me to wrap my form inputs with inputs_for.
I’m not entirely happy with this solution and am unsure if there’s a better method. I would like to hear your thoughts or any alternatives.
Most Liked
zachdaniel
It’s an interesting question. This works for updates because you have the Contract. You could try doing something like Ash.can?({%Contract{room: %Room{}}, :create}), but I’m not sure if the can? code will check for that on create.
Popular in Questions
Other popular topics
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









