Hey guys if I have my client state as
{ :list/id {:accounts { :list/accounts [ [:account/id 1] [:account/id 2] ....] } } }
I was trying to query for it w/ the following:
(db->tree [{:list/id [:accounts]}] {} (current-state SPA))
I'm getting {}
returned, I was wondering what would be the appropriate query to retrieve the list of accounts[{[:list/id :accounts] [{:list/accounts [*]}]}]
On a phone .. hard to input those
@alexander.890 (db->tree [{[:list/id :accounts] [{:list/accounts [*]}]}] (current-state SPA) (current-state SPA)) This should solve your question. The second arg to db->tree is the starting-entity which should not be an empty map. In most cases, querying from the root, you can use state-map i.e. (current-state SPA) as the starting-entity as well. Using the query shown by Tony, you use join to "drill down" into the subquery, where [*] is determined by your data design, for example [:account/name :account/status].
Just read Tony's new chapter on Core API and learnt something new. Turns out @tony.kay has already given you the full answer. By using ident [:list/id :account]
as a query element, you can indeed put an empty map as the starting-entity because the ident already provides the starting-entity. So, this works too:
(db->tree [{[:list/id :accounts] [{:list/accounts [*]}]}] {} (current-state SPA))
P.S. There are many ways to make this work. Long story short, check out Tony's new chapter, especially the section on denormalization: https://book.fulcrologic.com/#_denormalization
thank you, I think I should not nest it so much.
Thank you
I'll keep in mind to use current-state
for the starting-entity
So, I’ve added a new chapter, targeted at semi-beginners, to the book: https://book.fulcrologic.com/#_core_api
It encourages you to explore the core API of Fulcro with a simple CLJ REPL, and I hope it will help beginners gain an understanding of the very simple concepts at the center of Fulcro.
I know there’s a lot of material out there, and I keep trying to find a way to narrow people’s focus on what is truly core to understanding Fulcro. This chapter is my attempt at that.