Fork me on GitHub
#fulcro
<
2021-06-01
>
thosmos04:06:46

I’m using RAD (which is RAD!) and am attempting to add a reverse many-to-many reference to a report list. In other words, the report is listing station and each station can be referenced from multiple project records (:ref :many). On each station row, I’d like to have a set of project tags, and the ability to filter the report by project. I’m not sure how to configure this sort of “reverse many ref” into either the RAD attributes or the report config. I have reverse refs in my pathom resolvers outputs and underlying datomic query, so I can accomplish this with a query like:

[{:stations/all [:station/uuid :station/Name {:project/_Stations [:project/uuid]}]}]
which passes this to a datomic pull and it returns the appropriate data. What I don’t get is how to incorporate this kind of query into the RAD station report. Any tips?

thosmos04:06:03

Actually, I think this might be working. Any gotchas here?

(defattr Projects :project/_Stations :ref
  {ao/identities #{:station/uuid}
   ao/schema :production
   ao/target :project/uuid
   ao/cardinality :many
   ao/read-only? true})

thosmos00:06:25

Oh interesting, thanks for the link. I did #2, but then the column header was missing from the table. So I added an attribute for the reverse link, but then I made the mistake of linking it to the database schema, and couldn’t figure out how to skip the autogeneration of the schema for that attribute. I realized I needed to remove the ao/schema attribute. Now the report is working and I’m attempting to get a to-many control in the form editor to work.

thosmos03:06:25

I finally got it to work! I wound up needing to intercept the delta and rewrite it to change the owning side of the to-many references. https://github.com/thosmos/riverdb/blob/db4567b7eb957d9ee668525c8f48133421dd53e2/src/rad/riverdb/rad/middleware.cljc#L92

thosmos03:06:35

I wasn’t able to get the pathom attr resolver approach working like your example, but i already had that part working anyway. However, my approach for the resolvers would not work for the stock RAD setup because I use my own attribute specs to autogenerate my resolvers.

❤️ 3
Jakub Holý (HolyJak)11:06:29

[ANN] https://github.com/fulcro-community/fulcro-exercises has been made vastly clearer thanks to the awesome feedback I received from @alex-eberts Check out the latest version!

👏 9
3
Michael Mossinsohn19:06:54

Hi, Does anybody have any tips / best practice about combining a recursive attribute with Fulcro RAD? I tried using a normal defattr: (defattr parent :person/parent :ref {ao/target :person/id ao/cardinality :one ao/identities #{:person/id}}) I combined it with a picker which points to a defsc for its query: (defsc PersobParentQuery [ ] {:query (fn [] [:person/id {:person/parent 1}]) :ident :person/id }) It does not end well. :) Any ideas?

tony.kay00:06:19

In principle that is fine, but in practice I do not think I fully fleshed out recursive support. The resolver generation should be ok with it for Datomic (I think)...would be helpful for you to describe what "not ending well" means.

Michael Mossinsohn08:06:03

Thank you for your reply! and for the Fulcro ecosystem! 🙂 I think I get an infinite compiler loop. Since it's mentioned in the developers guide (inside the code for "Example 12. https://book.fulcrologic.com/#RecursiveDemo1") that "calling get query on yourself would lead to infinite compiler recursion", I suspected that circular recursion is not supported. (which is why I did't start by providing lots of details). Since it should be supported, It's probably me... 🙂 I will simplify my code and figure out if I can get my code to work or fail even with a more trivial case. If I can't get it to work I'll ask again for some guidance (and provide all the relevant details). Thanks! Michael

tony.kay13:06:00

You of course cannot call get-query (or any function) recursively without a termination condition...but where are you doing that? You used recursive query notation in your code sample

tony.kay13:06:57

Forms won't auto-handle it, but you have to do a subform join on a ref, which means generating a subform class. You cannot use the form itself as its own subform, but you can write another class for that purpose.