Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a notion of foreign keys #11

Open
chuwy opened this issue Oct 19, 2023 · 0 comments
Open

Add a notion of foreign keys #11

chuwy opened this issue Oct 19, 2023 · 0 comments

Comments

@chuwy
Copy link
Contributor

chuwy commented Oct 19, 2023

We can declare some members of a table class as "foreign keys", i.e. instead of an actual column in a table they're references to another relation-table. For example:

A persons table:

id first_name last_name
1  John       Smith  

A Person class:

case class Person(firstName: String, lastName: String, photos: List[Photo.Id])

Here, photos is a reference to persons_photos relation table:

person_id photo_id
1         1
1         2
1         3

So expressing this relation would look like:

Table
  .of[Person]
  .withName("persons")
  .withPrimary("id")
  .withForeign[Photo.Id]("photos", "id")
  .build

This way, whenever we do Person.table.get(personId) - it also queries all photos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant