fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Alex 2021-01-24T04:34:26.028100Z

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.kay 2021-01-24T05:57:22.029900Z

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

tony.kay 2021-01-24T05:59:22.030100Z

On a phone .. hard to input those

Henry 2021-01-24T06:39:58.042200Z

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

❤️ 1
Henry 2021-01-25T04:56:51.047400Z

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))

Henry 2021-01-25T05:29:45.048200Z

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

Alex 2021-01-24T07:00:52.042300Z

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

Alex 2021-01-24T07:02:19.042500Z

Thank you

Alex 2021-01-24T07:03:02.042700Z

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

tony.kay 2021-01-24T21:24:27.044100Z

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

❤️ 2
tony.kay 2021-01-24T21:25:14.044900Z

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.kay 2021-01-24T21:26:06.045900Z

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.

👍 3
👏 13
🙌 3