Any reason expressions are not supported in validations?
I would like to prevent an update action to be executed when a particular "sub-resource" has an attribute set to a particular value.
For example "mark order as complete only if its shipment is complete". So it would be nice to write it like this:
update :mark_complete do validate expr(shipment.status == :delivered) change set_attribute(:status, :done)end
update :mark_complete do validate expr(shipment.status == :delivered) change set_attribute(:status, :done)end
It looks like there's no built-in validation to do something like that. Of course, I can manually handle this in many different ways. But I'm wondering why it's not possible - there's probably a good reason.
Something like this is possible in policies though. Would a policy be a good candidate to implement this rule?
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.