Atom fields will save upcase atoms as downcase

I noticed that if I add an attribute like this:
attribute :currency, :atom do
allow_nil? false

constraints one_of: [:USD, :BRL, ...]
end
attribute :currency, :atom do
allow_nil? false

constraints one_of: [:USD, :BRL, ...]
end
And then save a :USD or :BRL value to it, when I retrieve the record, the value will be retrieved in lower case (ex. :BRL will be returned as :brl). Is this by design? In my case I want to store the currencies supported by the Money library, but they are all in upper case, meaning that when i get them back, they are considered invalid by the Money library.
3 Replies
ZachDaniel
ZachDaniel2y ago
Hmm… That sounds like a bug to me
ZachDaniel
ZachDaniel2y ago
I don’t see a place in the atom type that we change the casing: https://github.com/ash-project/ash/blob/v2.10.2/lib/ash/type/atom.ex#L1
GitHub
ash/lib/ash/type/atom.ex at v2.10.2 · ash-project/ash
A declarative and extensible framework for building Elixir applications. - ash/lib/ash/type/atom.ex at v2.10.2 · ash-project/ash
Blibs
BlibsOP2y ago
Ah, ignore it, I didn't add a unique constraint to my table, so the first row was saved with a down-case atom, and then it was creating new ones with the correct uppercase atom, but get was always fetching the first one..

Did you find this page helpful?