Now that the database connection is established, you can create your two entities
User entity will be the model used by the framework to identify users and the
Story entity will represent the users' posts.
user.entity.ts file from the
entities directory and add four new properties to your model:
avatar column will contain the paths to the profile images.
You will also need to export an additional model
DatabaseSession from the
@foal/typeorm package. You don't need to worry about it now, it will be used later in the tutorial when you add authentication.
Then create your second entity.
Open the new file and add three new properties:
By default, TypeORM allows many-to-one relationships to be nullable. The option passed to the decorator specifies that this one cannot be.
Finally, create the tables in the database. Generate the migrations from the entities and run them.
Three new tables are added to the database: the
story tables and a