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

Define one-to-one relation to non-primary (but unique) key in other table #588

Open
lbeuster opened this issue Nov 25, 2024 · 0 comments
Open

Comments

@lbeuster
Copy link

Hi,
I try to create a relation from MainTable to OtherTable that references MainTable not with its primary key, but with a unique key.

# pseudo-sql
MainTable(mainId: Int+Primary)
OtherTable(
    otherId: Int+Primary, 
    mainId: Int+Unique -> MainTable.mainId
)

# pseudo-ktorm
MainTable : Table {
    val mainId = int("mainId").primaryKey()
        .bindTo { it.mainId }
        .references(OtherTable) { it.otherTable }
}

MainEntity : Entity {
    var mainId: Int
    val otherTable: OtherTable
}

Currently it seems like the join from MainTable to OtherTable always uses the PK (otherId) of OtherTable, because I don't have the possibility to configure the column name of the OtherTable in the reference.

Is there a way to do this in the current version? Or could this be a feature request?

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