JetBrains / JetBrains/Exposed

Many-to-Many mapping with attributes

Open
#1,163 2 comments 8 reactions 1 assignee Claimed by @bog-walk View on GitHub
Dominant language
Kotlin
Stars
9.3k
Forks
798
Avg merge
4d 2h
Merged PRs (30d)
26

Description

Hello,
I have the following problem which I do not know how to solve.
I have "Candidates" as well as "Skills" which own have their own table and I want a many to many relationship between them where the "level" is an attribute of the table which links both Entities:

```kotlin
object Candidates: UUIDTable() {
val name = varchar("name", 50).index()
val age = short("age").nullable()
val created = datetime("created")
val updated = datetime("updated")
}

class Candidate (id: EntityID) : UUIDEntity(id) {
companion object : UUIDEntityClass(Candidates)
var name by Candidates.name
var age by Candidates.age
var skills by Skill via CandidateSkills
}

object CandidateSkills: Table() {
val candidate = reference("candidate", Candidates, onDelete = ReferenceOption.CASCADE).primaryKey(0)
val skillName = reference("skillName", Skills, onDelete = ReferenceOption.CASCADE).primaryKey(1)
val level = short("level")
}

object Skills: UUIDTable() {
val skillName = varchar("skill_name", 40).index()
}

class Skill(id: EntityID) : UUIDEntity(id) {
companion object : UUIDEntityClass(Skills)

var skillName by Skills.skillName
// How get this to work?
var level by CandidateSkill referencedOn CandidateSkills.level
}
```

The documentation does not mention how to reference such an attribute.

Could somebody help me please?

Best regards. Mike

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.