metabase / toucan

A classy high-level Clojure library for defining application models and retrieving them from a DB
Eclipse Public License 1.0
569 stars 49 forks source link

Use multimethods for custom hydration functions #31

Open camsaul opened 6 years ago

camsaul commented 6 years ago

Instead of tagging them with metadata it would be better if we could make them multimethods that dispatch off of the model as well as the key they are hydrating. That way different methods could be used to hydrate the same key for instances of different models. The approach also seems a little cleaner than having hydrate look through all namespaces for functions with matching metadata

There are two things that might make this tricky:

camsaul commented 5 years ago

I'm actually of the opinion that everything (including things like pre-insert!) should be implemented with multimethods instead of protocols. That would be a big breaking change, however.

tlrobinson commented 4 years ago

Is there a workaround for "different methods could be used to hydrate the same key for instances of different models"?