Fork me on GitHub

Howdy all, Coding novice here, after some data modeling feedback. Let's say I'm building a site that lists gift shops and the currencies they accept. I could store each currency code as a string in the store's document:

:store/id uuid
:store [:map {:closed true
[:store/currency [:vector  [:string]]]
but I imagine that could get messy (multiple opportunities for an admin to mistype a code etc). So my question is, where the data is both finite and known e.g currency codes. Is it better to create a new document and reference it by id.
:currency/id uuid
   :currency [:map {:closed true}
              [:currency/country :string]
              [:currency/code    :string]]

   :store/id uuid
   :store [:map {:closed true}
           [:store/currency  [:vector [:currency/id]]
           [:store/name                :string]]]  

Jacob O'Bryant23:11:37

Malli has an enum type that would work nicely. e.g. update first example to :store/currency [:enum :usd :eur ...]. If you're only dealing with a small total number of currencies, you could do that as-is. If you want to support all the currency codes, you could define them in a separate var, e.g. (def currencies [:usd :eur ...]) and then do :store/currency (into [:enum] currencies).


Super useful, thank you. Takes care of the follow up question I had WRT handling small vs large property lists

👌 1

If I wanted to bind the currency codes to their respective country names as strings:

(def currencies {:usd "United States"
Is this a sound approach:
:store/currency (into [:enum] (keys currencies)) 
With a view to rendering the countries name next to it's currency code in the DOM.

Jacob O'Bryant16:11:39

yes, that's a great way to do it

🙏 1