Fork me on GitHub
#fulcro
<
2017-09-17
>
tony.kay06:09:36

@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

claudiu06:09:50

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.

tony.kay06:09:55

:without removes elements from the query. load-field loads only one element of the current component’s query

tony.kay06:09:06

so they are complementary

tony.kay06:09:16

both can be used to “refresh” things

tony.kay06:09:17

neither knows anything but the query-at-hand…there is no dependency

tony.kay06:09:27

they just send a query to the server and merge in the result.

tony.kay06:09:20

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

tony.kay06:09:17

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)

tony.kay06:09:53

(load-field this :person/name) from Person sends something like [{[:person/by-id 3] [:person/name]}]

claudiu06:09:23

ahh cool 🙂 giving it a try now.

tony.kay06:09:25

which can be handled on the server with defquery-entity dispatched on :person/by-id

tony.kay06:09:35

and will receive ID 3

tony.kay06:09:53

The env will have [:person/name] as the query

claudiu06:09:41

makes sense, now. Will to rename my defquery-entitys for them to play nicely with load-field.

tony.kay06:09:29

you mean you were using defquery-root?

claudiu06:09:11

ahh yep 😞

tony.kay07:09:08

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.

tony.kay07:09:42

(load this [:person/by-id 3] Person) is “query everything the UI wants about person 3”

tony.kay07:09:14

(load-field this-person :person/name) is “query this person for their name (id is inferred from ident of this)”

tony.kay07:09:48

both make a join on an ident

tony.kay07:09:32

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.

tony.kay07:09:34

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.

tony.kay07:09:56

the graph query itself is ambiguous until it is “rooted”

claudiu07:09:54

🙂 trying it out. makes total sense now.

claudiu07:09:30

thank you 🙂

roklenarcic15:09:19

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?

roklenarcic15:09:56

I see that there is a transformation from - to _ somewhere but I don't know where it applies.

roklenarcic15:09:30

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?

tony.kay18:09:00

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

tony.kay18:09:52

The documentation talks about writing a driver, and the bits in there show you how you could further customize things for your own scenario.

tony.kay18:09:20

It’s a very small amount of code, so you should not be intimidated by the extension points, if you need them

tony.kay18:09:32

Now: many-to-many quantified joins. That is on the TODO list still 😞

tony.kay18:09:52

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)

tony.kay18:09:07

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”

tony.kay18:09:29

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

roklenarcic21:09:47

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.