This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-17
Channels
- # beginners (51)
- # boot (31)
- # cider (14)
- # clara (13)
- # cljs-dev (15)
- # cljsjs (2)
- # cljsrn (53)
- # clojure (18)
- # clojure-dusseldorf (1)
- # clojure-russia (4)
- # clojure-uk (9)
- # clojurescript (53)
- # cursive (3)
- # datomic (5)
- # docs (1)
- # figwheel (2)
- # fulcro (42)
- # hoplon (3)
- # lein-figwheel (3)
- # leiningen (53)
- # off-topic (1)
- # om (4)
- # re-frame (11)
- # shadow-cljs (8)
@claudiu Dev Guide section H on Server interactions. load-field
is what you want, along with :without
on load
. The whiteboard video about data loading and lifecycle also talks about this case, I believe
https://www.youtube.com/watch?v=mT4jJHf929Q&list=PLVi9lDx-4C_T_gsmBQ_2gztvk6h_Usw6R&index=8
Will give it a try, was under the impresion that I have to do a load for that componentend with without, for load-field to work.
:without
removes elements from the query. load-field
loads only one element of the current component’s query
load sends the entire query, unless you prune it with :without
. load-field
prunes everything except the indicated element from the query. They differ only in how they manipulate (generate) the query to be sent
Well, and you must know that load-field
sends an ident-based join as the query (with the ident of the current component, which must have an ident for it to work)
(load-field this :person/name)
from Person
sends something like [{[:person/by-id 3] [:person/name]}]
makes sense, now. Will to rename my defquery-entitys for them to play nicely with load-field.
yeah, so ident-based queries are defquery-entity
, since that is what you are querying: an entity. When you use an ident with load
(or use load-field
) they will always hit that.
(load this [:person/by-id 3] Person)
is “query everything the UI wants about person 3”
(load-field this-person :person/name)
is “query this person for their name (id is inferred from ident of this)”
which means your server-side “root set” for the query is a specific entity in your storage, thus defquery-entity
. Whereas (load this :things Thing)
is a more abstract root set of thing(s)…thus defquery-root
.
The concept of “root set” is similar to that of the mark phase of garbage collection mark-and-sweep (if you know anything about that). I use the term here because your query is a graph query that might pull all sorts of data in a tree…rooted at the root set.
I'm a bit confused about naming in fulcro sql. My database columns have underscores, my schema column names need to also have underscores? And my query properties in defui have to have hyphens?
I see that there is a transformation from -
to _
somewhere but I don't know where it applies.
What do I do about many-to-many joins with are quantified in some way? Tables like [person_id trans_id amount(numeric)]
or [person_id trans_id active(boolean)]
where I don't want non-active links in my result?
@roklenarcic The hypen to underscore is the default transform on properties. So, you can use hyphens in clj, and they will automatically become underscores at the db layer (and vice versa)
The documentation talks about writing a driver, and the bits in there show you how you could further customize things for your own scenario.
It’s a very small amount of code, so you should not be intimidated by the extension points, if you need them
I have an example commented out in the tests, but I have not decided exactly how to support them because there are a number of variations of what you’d want. In some case, it’s just a filter (which you don’t represent in your graph), in other cases you actually want the data (as in your amount example)….but you probably don’t want an explicit graph level for just that data, you’d like it to go to one level or another (as if it were store on the target table, for example)
I’m not sure if that makes logical sense in all cases, which is part of the reason I have not implemented it yet. At the moment, that is a case I expect you to do “by hand”
If you care to explore it with me, I’d feel more confident in the solution. Feel free to comment here: https://github.com/fulcrologic/fulcro-sql/issues/2
By hand is fine I'm making a very small app first. In production level DB schemas, there usually a lot of columns which deal with history tracking and effectivity. That is, it is very common to have deleted (bool)
column instead of actually deleting things, version
columns (I think ORM solutions like hibernate use those extensively to detect concurrent updates) or sometimes effective_from
effective_to
columns. Sometime those things are even in many-to-many mapping tables. Another thing that is sometimes in many-to-many mapping tables is relationship_type
columns. Typically you want those things to be added to whatever the list item is.