Fork me on GitHub
#fulcro
<
2021-01-24
>
Alex04:01:26

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

tony.kay05:01:22

[{[:list/id :accounts] [{:list/accounts [*]}]}]

tony.kay05:01:22

On a phone .. hard to input those

Alex07:01:52

thank you, I think I should not nest it so much.

Henry06:01:58

@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].

❤️ 3
Alex07:01:19

Thank you

Alex07:01:02

I'll keep in mind to use current-state for the starting-entity

Henry04:01:51

Just read Tony's new chapter on Core API and learnt something new. Turns out @U0CKQ19AQ 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))

Henry05:01:45

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

tony.kay21:01:27

So, I’ve added a new chapter, targeted at semi-beginners, to the book: https://book.fulcrologic.com/#_core_api

❤️ 6
tony.kay21:01:14

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.

tony.kay21:01:06

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.

👏 39
🙌 9
👍 9
Henry05:01:58

The new chapter is more than helpful. Full of gems, simply outstanding. Many thanks @U0CKQ19AQ for sharing your knowledge and wisdom with us.