Primary / foreign key join inference

Conrad Slimmer · Friday Demos · August 8, 2025 · 4:35

We made our join inference a little smarter by reading the DB metadata to build a more comprehensive join library.

Transcript

This transcript is auto-generated. Names and product terms may be wrong.

  1. Okay, myself unmuted and on video. How's everybody doing this morning? Um, just get my screen situated. Okay, so I just did a quick little kind of background project that's kind of cute um that hopefully be able to work out the kinks uh sometime next week and get it into the product. But essentially uh in today's model generator, we generate your um your relationships based on some pretty naive um guessing about the names of columns.

  2. um and other tables that are in your database schema. And so um we're looking at making a little enhancement to um infer relationships from foreign keys. So now when this lands, you'll have the option to specify that you want to infer your relationships from foreign keys. I'll go ahead and do that. And uh I'll actually update the connection so that things work.

  3. And if I uh jump in here, you can see this is the schema model that we're looking at the relationships file. Uh and over in let me see if I can find Docker. You can just just to show I've added this um this foreign key constraint uh from orders. seller ID on user ID in our test data.

  4. We have this column in the orders table called seller ID. Uh and we currently don't uh actually generate a relationship based on that. So if I come back into here the connection and I do a schema refresh now that I've checked this we will actually uh read the foreign key constraints and I'll refresh this and you can see that we are now generating a relationship from orders to users on seller ID and the little nuance here is that that's an alias relationship so there's there's some work to do to like make sure that I'm generating a decent alias name for for these things when there's another um another relationship that like in this case we've got two relationships from orders to users.

  5. So I don't want to just call it users because they'd be duplicate. Anyway, uh thought it was cute. Wanted to share hopefully uh get that into the product sometime next week. All right. any uh dialect limitations there? Uh yeah, that's I mean that's the other bit of work. I've done the fun part which is like to make it work and now I have to go through and do all the pedantic stuff of like figuring out which dialects uh actually support um even creating foreign key uh uh constraints uh and whether we're and then like go through and you know do the stuff to to test it and make sure that if we say that we support it we're actually uh reading those and if we

  6. don't support it hide that uh that setting on those dialects etc., etc. So, you know, there's kind of the the long tale of of uh of making it um you know, really product ready and and and work where it work where it should work and not allow people to do it where maybe it shouldn't work. I mean, one example is like Snowflake.

  7. Um you can create foreign keys in Snowflake. Uh, but there's some chatter on the internet and I haven't actually gone and done the test with Snowflake yet to see, but that says that the like get foreign key constraints in the JDBC driver that we use may or may not work and stuff. So, there's like little fiddly things that we have to sort out.

  8. I think it should work on Snowflake though. That's my next my next step because I know that's that's the one where we're like, "Oh, we've got somebody who actually wants that.