Fork me on GitHub
#fulcro
<
2017-10-05
>
myguidingstar14:10:22

hi, I'm still learning fulcro. I'm curious how to do nornalization and queries for the case of many-to-many pattern

myguidingstar14:10:17

{:authors/by-id {"author/1" {:db/id       "author/1"
                             :author/name "Foo"}
                 "author/2" {:db/id       "author/2"
                             :author/name "Bar"}}
 :books/by-id   {"book/1" {:db/id       "book/1"
                           :author/name "A book"}
                 "book/2" {:db/id      "book/2"
                           :book/title "The book"}}
 :books_authors/by-id
 {"books_authors/1" {:db/id  "books_authors/1"
                     :author [:authors/by-id "author/1"]
                     :book   [:books/by-id "book/1"]}
  "books_authors/2" {:db/id  "books_authors/2"
                     :author [:authors/by-id "author/1"]
                     :book   [:books/by-id "book/2"]}}}

myguidingstar14:10:16

should I have a junction table like above?

myguidingstar14:10:18

if yes, then what the query for author and book should look like?

myguidingstar14:10:34

if no, then what is the right way to do it?

fatihict22:10:59

@myguidingstar You could simply store a key like :book/author in books/by-id pointing to authors like [:authors/by-id "author/1"]. I would give the excellent online docs here a read: https://fulcrologic.github.io/fulcro/guide.html#!/fulcro_devguide.C_App_Database or you can clone the Fulcro repo https://github.com/fulcrologic/fulcro and run ./run-devguide.sh in order to be able to play with the devcards as well. When you're reading up on that section I would take note on naming conventions used to reduce redundancy in your example e.g. I would expect an id of 1 instead of "author/1".