eager: boolean
- If set to true, the relation will always be loaded with the main entity when using find*
methods or QueryBuilder
on this entitycascade: boolean | ("insert" | "update")[]
- If set to true, the related object will be inserted and updated in the database. You can also specify an array of cascade options.onDelete: "RESTRICT"|"CASCADE"|"SET NULL"
- specifies how foreign key should behave when referenced object is deletedprimary: boolean
- Indicates whether this relation's column will be a primary column or not.nullable: boolean
- Indicates whether this relation's column is nullable or not. By default it is nullable.orphanedRowAction: "nullify" | "delete" | "soft-delete"
- When a child row is removed from its parent, determines if the child row should be orphaned (default) or deleted (delete or soft delete).save
for category1
and category2
. They will be automatically inserted, because we set cascade
to true.cascade
option can be set as a boolean
or an array of cascade options ("insert" | "update" | "remove" | "soft-remove" | "recover")[]
.false
, meaning no cascades. Setting cascade: true
will enable full cascades. You can also specify options by providing an array.@JoinColumn
options@JoinColumn
not only defines which side of the relation contains the join column with a foreign key, but also allows you to customize join column name and referenced column name.@JoinColumn
, it automatically creates a column in the database named propertyName + referencedColumnName
. For example:categoryId
column in the database. If you want to change this name in the database you can specify a custom join column name:@JoinColumn
as well:name
of the Category
entity, instead of id
. Column name for that relation will become categoryName
.@JoinTable
options@JoinTable
is used for many-to-many
relations and describes join columns of the "junction" table. A junction table is a special separate table created automatically by TypeORM with columns that refer to the related entities. You can change column names inside junction tables and their referenced columns with @JoinColumn
: You can also change the name of the generated "junction" table.@JoinTable
.