// typeorm set relation (One-To-One-Relation)
// "Video" is the main table
// "channel" is the relation variable
await connection.createQueryBuilder()
.relation(Video, "channel")
.of(Number(id)) // video id
.set(Number(channelId))
/*
* Loads id (or ids) of specific relations into properties.
* For example, if you have a many-to-one category in your
* Post entity, you can have a new category id by marking
* a new property with @RelationId. Example:
*/
@Entity()
export class Post {
@ManyToOne(type => Category)
category: Category;
@RelationId((post: Post) => post.category) // you need to specify target relation
categoryId: number;
}
/*
* Loads id (or ids) of specific relations into properties.
* For example, if you have a many-to-one category in your
* Post entity, you can have a new category id by marking
* a new property with @RelationId. Example:
*/
@Entity()
export class Post {
@ManyToOne(type => Category)
category: Category;
@RelationId((post: Post) => post.category) // you need to specify target relation
categoryId: number;
}