sql

Dustin Getz (Hyperfiddle) 2025-02-19T19:03:09.702079Z

Hi, how do I teach next.jdbc's nav implementation about a many-many join table? Here is a working ordinary join for the sakila example dataset. And I want to navigate through {:film_actor/_film_id :actor/actor_id} . Specific qs: β€’ what attribute am I meant to hang the navigate on? β€’ how do i express the two step join?

Dustin Getz (Hyperfiddle) 2025-02-19T19:03:30.366309Z

I did read https://github.com/seancorfield/next-jdbc/blob/develop/doc/datafy-nav-and-schema.md which says > When you indicate a *-to-many relationship, by wrapping the foreign table/key in a vector, next.jdbc's implementation of nav will fetch a multi-row result set from the target table. which led me to try the following, but clearly I am missing some key concept

:film/actors [:film_actor/_film_id]
:film/actors {:film_actor/_film_id :actor/actor_id}
:film/film_id {:film_actor/_film_id :actor/actor_id}

Dustin Getz (Hyperfiddle) 2025-02-19T19:05:43.476029Z

Dustin Getz (Hyperfiddle) 2025-02-19T19:11:05.144689Z

this mapping seems coherent but it is in the wrong direction, there is no named key for the outbound edge from the film entity

{:film/language_id :language/language_id
 :actor/actor_id :film_actor/_actor_id
 :film/film_id :film_actor/_film_id}

seancorfield 2025-02-19T19:34:10.759579Z

If you have table1 and table2 and a m2m join table with table1_id and table2_id columns, you still have two transitions for next.jdbc schema nav: table1 to (multiple) m2m rows and then from each m2m row to table2. There's no support for making multiple "jumps" in a single nav.

πŸ‘€ 1
seancorfield 2025-02-19T19:39:24.531629Z

That :table1/col1 {...} hash map syntax is not valid currently. Only :table1/col1 :table2/col2 or :table1/col1 [:table2/col2]

πŸ‘€ 1
seancorfield 2025-02-19T19:40:08.623309Z

Feel free to create a GH issue outlining how you'd like to be able to specify a many-to-many double-jump.

Dustin Getz (Hyperfiddle) 2025-02-20T21:52:04.699729Z

Ok, thanks makes sense. We may think about how one might specify and implement thisβ€”unless you already have and you decided the semantics are unsound?β€”but it might be a while

seancorfield 2025-02-20T22:01:48.207389Z

I had not considered it -- the two-step nav has always seemed fine to me...

πŸ‘ 1
Dustin Getz (Hyperfiddle) 2025-02-20T22:06:43.270049Z

when you nav from film to film_actor, which outbound column do you put the nav on? film/film_id? i.e. {:film/film_id :film_actor/_film_id} ?

seancorfield 2025-02-20T22:08:27.764629Z

The schema should map from film/film_id to film_actor/filmid and from film_actor/actorid to actor/actor_id I assume, based on what seem to be your conventions?

Dustin Getz (Hyperfiddle) 2025-02-20T22:09:25.409959Z

what if there is a second join table also connected to film/film_id, such as film->directors "many films each have many directors"

seancorfield 2025-02-20T22:09:38.441809Z

So I guess you want {:film/film_id [:film_actor/_film_id] :film_actor/_actor_id :actor/actor_id} (since film -> film_actor is 1:n)

πŸ‘ 1
seancorfield 2025-02-20T22:10:09.630159Z

You can only auto nav one relationship.

πŸ‘ 1
seancorfield 2025-02-20T22:10:31.684839Z

Remember, this whole datafy/nav stuff is a convenience for development. It's not intended for "real code".

Dustin Getz (Hyperfiddle) 2025-02-20T22:11:06.067149Z

got it, yeah i'm with you on that -- context is we're implementing web based rebl thing as an experiment

seancorfield 2025-02-20T22:11:59.839579Z

Then you'll be in the same bucket as Morse, Reveal, and Portal in terms of using datafy/nav and having it do whatever the underlying data and tooling has made available.

Dustin Getz (Hyperfiddle) 2025-02-20T22:12:44.011139Z

we have made some interesting upgrades, but that's neither here nor there

seancorfield 2025-02-20T22:12:57.249519Z

Those viewing tools don't really have any control over how datafy/nav works for any given data, beyond perhaps extending certain (Java) types for additional datafication and navigation.

πŸ‘ 1