How to create an atomic validation for the amount on AshMoney?
I have an attribute using AshMoney like so:
And I'd like to validate that the amount part is non-zero, ignoring the currency. I've managed to create a custom validation for it but it's not atomic:
9 Replies
I think if you have the postgres extension installed, you should just be able to compare against the value 0
This does compile:
However it doesn't seem to block the creation of the resource
can you try
attribute_does_not_equal
insteadCool, that works 🙂
Another question: Is it possible to do the same on an aggregate?
I got this:
And
you could try to do your own validation moduel that mirrors this one https://github.com/ash-project/ash/blob/v3.5.34/lib/ash/resource/validation/attribute_does_not_equal.ex but only has a atomic callback.
GitHub
ash/lib/ash/resource/validation/attribute_does_not_equal.ex at v3.5...
A declarative, extensible framework for building Elixir applications. - ash-project/ash
I think the problem is that it tries to do the regular validate in your case and there the value is not loaded
Okay, cool.
Thanks again!
GitHub
ash/lib/ash/resource/validation/attribute_equals.ex at v3.5.34 · a...
A declarative, extensible framework for building Elixir applications. - ash-project/ash
or this one is the one you used