From b0b20e64933d7fe83cbc14dccd7f4ac88c1fdaee Mon Sep 17 00:00:00 2001 From: silverqx Date: Tue, 17 May 2022 15:17:34 +0200 Subject: [PATCH] docs use make:seeder to generate seeders --- docs/building-migrations.mdx | 6 ++++++ docs/seeding.mdx | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/docs/building-migrations.mdx b/docs/building-migrations.mdx index 69ca2af25..d5c87a3cc 100644 --- a/docs/building-migrations.mdx +++ b/docs/building-migrations.mdx @@ -276,6 +276,12 @@ If you want, you can also build the `tom` application without the migrations, si ### Seeders +If you have already built the `tom` application then you can generate a seeder using the [`make:seeder`](seeding.mdx#writing-seeders) command 😎. + +```bash +tom make:seeder PostSeeder +``` + The expected folders structure is described a few paragraphs [above](#folders-structure). The [`seeders.pri`](#seeders-source-files) file is used only by the `qmake` build system and is not needed with `CMake` builds. Let's create the root seeder class manually. diff --git a/docs/seeding.mdx b/docs/seeding.mdx index f5da09e4d..07e22eb99 100644 --- a/docs/seeding.mdx +++ b/docs/seeding.mdx @@ -20,6 +20,16 @@ TinyORM includes the ability to seed your database with data using seed classes. ## Writing Seeders +To generate a seeder, execute the `make:seeder` `tom` command. A new seeder will be placed in the `database/seeders` directory relative to the current pwd: + +```bash +tom make:seeder UserSeeder +``` + +:::tip +You can omit the `Seeder` word in the class name, `tom` appends it for you. +::: + A seeder class only contains one method by default: `run`. This method is called when the `db:seed` tom command is executed. Within the `run` method, you may insert data into your database however you wish. You may use the [query builder](query-builder.mdx#insert-statements) to manually insert data. As an example, let's modify the default `DatabaseSeeder` class and add a database insert statement to the `run` method: