docs use make:seeder to generate seeders

This commit is contained in:
silverqx
2022-05-17 15:17:34 +02:00
parent ca93cd31a0
commit b0b20e6493
2 changed files with 16 additions and 0 deletions
+6
View File
@@ -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.
+10
View File
@@ -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 <abbr title='Current working directory'>pwd</abbr>:
```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: