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

Many-to-Many mapping with attributes #1163

Open
ZronekM opened this issue Feb 9, 2021 · 2 comments · May be fixed by #2204
Open

Many-to-Many mapping with attributes #1163

ZronekM opened this issue Feb 9, 2021 · 2 comments · May be fixed by #2204
Assignees

Comments

@ZronekM
Copy link

ZronekM commented Feb 9, 2021

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:

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<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<Candidate>(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<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<Skill>(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

@1fexd
Copy link

1fexd commented Feb 19, 2021

Hi, I have had the same problem in the past, but my issue @ #928 has not been addressed. Kind of sad actually, since this is a really good ORM, but without basic SQL functionality it is not suitable at all for larger projects, so I suggest you switch to something else if you plan on doing more complex things than having a few int-id-PK tables.

@kapstahillar
Copy link

Has anyone found a workaround for it yet? Earlier today i said nice things about JetBrains, but now seeing that ORM system cannot do basic thing like that, makes me think another way. It has been a year from last comment...

@bog-walk bog-walk self-assigned this Jul 29, 2024
@bog-walk bog-walk linked a pull request Aug 16, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants