Other kinds of relationships
So far we’ve explored “one-to-many” relationships. Obviously, TypeORM supports “one-to-one” and “many-to-many” relationships as well.
One-to-one
Just in case you’re not familiar with this kind of relationships, the idea behind it is that one instance of an entity, and only one, belongs to one instance, and only one, of another entity.
To give a more specific example, let’s imagine that we were going to create a new EntryMetadata
entity to store new things that we want to keep track of, like, let’s say, the number of likes a blog entry got from readers and a shortlink for each blog entry.
Let’s start by creating a new entity called EntryMetadata
. We will put the file in the /entry
folder, next to the entry.entity.ts
file.
src/entries/entry_metadata.entity.ts
import
{
Entity
,
PrimaryGeneratedColumn
,
Column
}
from
'typeorm'
;
@
Entity
()
export
class
EntryMetadata
{
@
PrimaryGeneratedColumn...