Last active
December 5, 2022 06:11
-
-
Save umar-muneer/628f2ee30093f1ba8d7427ed2b5788f6 to your computer and use it in GitHub Desktop.
Mikro-orm Many to Many
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity({ | |
tableName: 'folders', | |
}) | |
export class FolderEntity { | |
@ManyToMany({ | |
entity: () => Project, | |
pivotEntity: () => VisionProjectsFolderEntity, | |
joinColumn: 'folder__id', // this property is important to provide, it is the column where we will go and query the pivot table | |
}) | |
projects = new Collection<Project>(this); | |
} | |
@Entity({ | |
tableName: 'projects', | |
}) | |
export class ProjectEntity { | |
// defining this side of the relationship is optional, only if we need to retrieve folders through projects | |
@ManyToMany({ | |
entity: () => Folder, | |
pivotEntity: () => VisionProjectsFolderEntity, | |
joinColumn: 'project__id', // this property is important to provide, it is the column where we will go and query the pivot table | |
}) | |
projects = new Collection<Project>(this); | |
} | |
@Entity({ | |
tableName: 'projects_folders', | |
}) | |
export class ProjectsFoldersEntity extends TransectBaseEntity { | |
@ManyToOne({ entity: () => FolderEntity, joinColumn: 'folder__id' }) | |
folder!: FolderEntity; | |
@ManyToOne({ entity: () => Project, joinColumn: 'project__id' }) | |
project!: Project; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment