Ash FrameworkAF
Ash Framework6mo ago
7 replies
arconaut

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


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?
Was this page helpful?