Fork me on GitHub
Thomas Moerman10:10:48

Cool talk by Malcolm Sparks, strikes close to the RAD philosophy:


Just the last three minutes?


Can I use union queries if the key I want to switch is not the entity’s :ident? To clarify, lots of my entities share a common :db/id that they use for their :ident, but I have a component that uses a case expression on a different key in order to decide what to render. It seems that union queries assume it’s the ident that is the switching key…


No. Union queries have no other information available BUT the ident during denormalization, and they have to use that to decide which of the union elements is the subquery. Using native IDs in the data model is fine, but it is better to give each ID an entity-specific name at the resolver layer. You could also give each entity a "type" field of some kind, and generate idents that way (use the type field as the first element of the idents).


That makes sense. Thanks Tony.


BTW: a concat of get-query will almost never do what you want. The resulting query will have metadata that only knows the ident function of the container, which will break normalization in 99% of cases...e.g. won't do the right thing if you were to load or merge using that component as the normalizing component


Oh that’s good to know, thanks for the heads up. I ended up solving it at the resolver layer as you suggested.


I got this working:

:query (fn [] (concat (comp/get-query EntityA) (comp/get-query EntityB) ...))
But it feels less than ideal (lots of wasted query computing)


I can see why it works this way. Bit of a chicken-or-the-egg problem, or what’s available and when. Wondering if there’s a better way than the above.


(The answer might be “don’t have everything use :db/id”. This just happened to be the most convenient way to import this data into Fulcro.)