ufoss-org / kotysa

The idiomatic way to write type-safe SQL in Kotlin
The Unlicense
117 stars 1 forks source link

Support nullable foreign keys #153

Open sengokudaikon opened 5 months ago

sengokudaikon commented 5 months ago

I would like to request adding support for nullable FKs. At least in Postgres, a FK that's nullable doesn't reference any PK and is therefore valid. This would allow mapping optional relations to the entities, as sometimes it's required.

protected fun <U : AbstractDbColumn<T, *>, V : Any?> U.nullableForeignKey(
        references: AbstractDbColumn<V, *>,
        fkName: String? = null,
    ): U =
        this.also {
            kotysaForeignKeys.add(ForeignKey(mapOf(this to references), fkName))
        }

maybe something like this?

If the feature is already possible to implement, please tell, because I couldn't find it in the documentation