ktorm icon indicating copy to clipboard operation
ktorm copied to clipboard

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

Open lbeuster opened this issue 1 year ago • 0 comments

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?

lbeuster avatar Nov 25 '24 10:11 lbeuster