Skip to content

Instantly share code, notes, and snippets.

@Yangeok
Last active December 13, 2020 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yangeok/17fc7db8c3a3c04fd766d06936334055 to your computer and use it in GitHub Desktop.
Save Yangeok/17fc7db8c3a3c04fd766d06936334055 to your computer and use it in GitHub Desktop.
typeorm-service-helper
import { getConnection, BaseEntity } from 'typeorm'
export function getRelation(Entity: typeof BaseEntity, id, relation) {
return getConnection()
.createQueryBuilder()
.relation(Entity, relation)
.of(id)
}
export function getRelationOfUser(userId, relation) {
return getRelation(User, userId, relation)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment