Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typeorm RelationId

/*
* 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;

}
Source by orkhan.gitbook.io #
 
PREVIOUS NEXT
Tagged: #typeorm #RelationId
ADD COMMENT
Topic
Name
8+5 =