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

autoIncrement carries to referencing column #385

Closed
brezinajn opened this issue Sep 11, 2018 · 2 comments
Closed

autoIncrement carries to referencing column #385

brezinajn opened this issue Sep 11, 2018 · 2 comments

Comments

@brezinajn
Copy link

object Foo: IdTable<Long>(){
    override val id = long("id").autoIncrement().entityId().primaryKey()
}

object Bar: IdTable<Long>(){
    override val id = long("id").autoIncrement().entityId().primaryKey()
}

object Baz: Table(){
    val fooId = reference("fooId", Foo.id)
    val barId = reference("barId", Bar.id)
}

this creates SQL

CREATE TABLE IF NOT EXISTS Baz (
  fooId     BIGINT AUTO_INCREMENT NOT NULL,
  barId     BIGINT AUTO_INCREMENT NOT NULL
...

which cannot succeed. Without the autoIncrement in parent tables everything goes fine.

@brezinajn
Copy link
Author

Ugly workaround

object Baz: Table(){
    val fooId = reference("fooId", Foo.id)
    val barId = reference("barId", Bar.id)

    override fun createStatement(): List<String> = super.createStatement()
            .map { it.replace("AUTO_INCREMENT", "") }
}

@Tapac
Copy link
Contributor

Tapac commented Sep 12, 2018

Thank you for a report. Fixed in master.
BTW, you can replace your workaround with:

object Baz: Table(){
    val fooId = reference("fooId", Foo)
    val barId = reference("barId", Bar)
}

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

2 participants