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 KEY JOIN syntax to simulate joining using generated foreign keys #578

Closed
lukaseder opened this issue Jul 22, 2012 · 0 comments
Closed

Comments

@lukaseder
Copy link
Member

If two entites are formally related using a foreign key relationship, it is only natural for users to join them:

create.select()
      .from(T_AUTHOR)
      .join(T_BOOK).on(TAuthor.ID.equal(TBook.AUTHOR_ID));

This can become tedious after a while. If foreign key relationships are formally available to jOOQ, then any of these "virtual" syntaxes could be imagined:

// Let the user assume that the key exists.
// Throw exceptions if there is no key in T_BOOK referencing 
// T_AUTHOR (the order is important), or if keys are ambiguous
// Additional conditions can be added to the generated ON clause
create.select()
      .from(T_AUTHOR)
      .join(T_BOOK)
      .onKey()
     [.and() | .or() | ...]

// Let the user provide a explicitly.
// This will throw an exception if the provided key does not
// link T_BOOK to T_AUTHOR or vice versa (the order isn't important)
// Additional conditions can be added to the generated ON clause
create.select()
      .from(T_AUTHOR)
      .join(T_BOOK)
      .onKey(Keys.FK_1)
     [.and() | .or() | ...]

// Or let them provide fields that participate in a key
// This will throw an exception if the provided fields do not
// fully participate in a key that links T_BOOK to T_AUTHOR or vice
// versa (the order isn't important)
// Additional conditions can be added to the generated ON clause
create.select()
      .from(T_AUTHOR)
      .join(T_BOOK)
      .onKey(TBook.AUTHOR_ID, ...)
     [.and() | .or() | ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant