Skip to content

Commit

Permalink
docs section about call with additional arguments
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
silverqx committed May 17, 2022
1 parent f7ecb55 commit 153aac6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/building-migrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ And paste the following code.
} // namespace Migrations

:::info
If you want, you can also build the `tom` application without the migrations, simply comment out the `migrations()` method and the corresponding `#include "migrations/xyz.hpp"` files.
If you want, you can also build the `tom` application without the migrations, simply comment out the `migrations` method and the corresponding `#include "migrations/xyz.hpp"` files.
:::

### Seeders
Expand Down
2 changes: 1 addition & 1 deletion docs/database.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Some database statements do not return any value. For these types of operations,
DB::statement("drop table users");

:::tip
`DB::statement()` should be used for [DDL](https://en.wikipedia.org/wiki/Data_definition_language) queries, don't use it for "select" queries because it internally calls `recordsHaveBeenModified()`.
`DB::statement` method should be used for [DDL](https://en.wikipedia.org/wiki/Data_definition_language) queries, don't use it for "select" queries because it internally calls `recordsHaveBeenModified` method.
:::

#### Running An Unprepared Statement
Expand Down
2 changes: 1 addition & 1 deletion docs/dependencies.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Qt framework version used during development was 5.15.2 and >= 6.2.

Optional:

- [MySQL Connector/C 8](https://dev.mysql.com/downloads/c-api/) - used only for the [`mysql_ping()`](https://dev.mysql.com/doc/c-api/8.0/en/mysql-ping.html) function and provided by [MySQL 8 Server](https://dev.mysql.com/downloads/mysql/)
- [MySQL Connector/C 8](https://dev.mysql.com/downloads/c-api/) - used only for the [`mysql_ping`](https://dev.mysql.com/doc/c-api/8.0/en/mysql-ping.html) function and provided by [MySQL 8 Server](https://dev.mysql.com/downloads/mysql/)

### Install dependencies

Expand Down
36 changes: 36 additions & 0 deletions docs/seeding.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,42 @@ Within the `DatabaseSeeder` class, you may use the `call` method to execute addi
call<UserSeeder, PostSeeder, CommentSeeder>();
}

#### Call with additional arguments

The `call` method allows to pass additional arguments to the seeder/s, but it has additional requirements.

If you define a `run` method without parameters then this method is called using the virtual dispatch (polymorphism) and in this case, you should use the `override` specifier.

If you define your `run` method eg. like this `run(bool shouldSeed)` or whatever parameters you want, then this method is called using the fold expression (virtual dispatch is not used in this case) so you can't use the `override` specifier and you must call the `call<>()` method with exactly the same arguments like the `run` method was defined with, in our example, it should look like this `call<ExampleSeeder>(true)`.

Let's demonstrate it on a small example, following is the `run` method in the root `DatabaseSeeder` class.

/*! Run the database seeders. */
void run() override
{
// This value can be based eg. on data from the database
const auto shouldSeed = true;

call<UserSeeder>(shouldSeed);
}

The `run` method in the `UserSeeder` class.

/*! Run the database seeders. */
void run(const bool shouldSeed)
{
if (!shouldSeed)
return;

DB::table("users")->insert({
{"name", "1. user"},
});
}

:::tip
The `call` method provides two shortcut methods, `callWith` and `callSilent` (no output from seeders).
:::

## Running Seeders

You may execute the `db:seed` tom command to seed your database. By default, the `db:seed` command runs the `Seeders::DatabaseSeeder` class, which may in turn invoke other seed classes. However, you may use the `--class` option to specify a specific seeder class to run individually:
Expand Down

0 comments on commit 153aac6

Please sign in to comment.