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

Join on two tables with more than one foreign key constraint fails even with additionalConstraint #522

Closed
rabolfazl opened this issue Mar 18, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@rabolfazl
Copy link

rabolfazl commented Mar 18, 2019

Consider the following:

class User(id: EntityID<Int>) : IntEntity(id) {
    companion object : IntEntityClass<User>(Users)
}

object Users : IntIdTable() {
}

class Subscription(id: EntityID<Long>) : LongEntity(id) {
    companion object : LongEntityClass<Subscription>(Subscriptions) {
    var user by User referencedOn Subscriptions.user
    var adminBy by User optionalReferencedOn Subscriptions.adminBy
}

object Subscriptions : LongIdTable() {
    val user = reference("user", Users)
    val adminBy = reference("adminBy", Users).nullable()
}

The following join query fails:

Subscriptions.join(Users, JoinType.INNER, additionalConstraint = {Subscriptions.user eq Users.id})

The problem is in file org.jetbrains.exposed.sql.Table.kt on line 92 (0.13.3):

else -> return join(otherTable, joinType, fkKeys.map { it.first to it.second.single() }, additionalConstraint)

it.second.single() fails while according to previous lines, when additional constraints are specified, it.second() may have more than one element so .single() fails.

@Tapac Tapac self-assigned this Mar 21, 2019
@Tapac Tapac added the bug label Mar 21, 2019
@Tapac Tapac added this to the 0.13.4 milestone Mar 21, 2019
Tapac added a commit that referenced this issue Mar 21, 2019
@Tapac
Copy link
Contributor

Tapac commented Mar 22, 2019

In your case it's better to use:
Subscriptions.innerJoin(Users, { user }, { id }) but it's unrelated to a bug you mentioned.

@Tapac Tapac closed this as completed Mar 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants