@@ -859,10 +859,15 @@ You can parse this output to make form fields show up with a red border and thei
859859
860860Two forms of multi-tenancy are supported:
861861
862+ - Single database, where every table has a tenant column (using the "multiTenancy" middleware).
863+ - Multi database, where every tenant has it's own database (using the "reconnect" middleware).
864+
865+ Below is an explanation of the corresponding middlewares.
866+
862867#### Multi-tenancy middleware
863868
864- You may use the "multiTenancy" middleware when you have a multi-tenant database.
865- If your tenants are identified by the "customer_id" column you can use the following handler:
869+ You may use the "multiTenancy" middleware when you have a single multi-tenant database.
870+ If your tenants are identified by the "customer_id" column, then you can use the following handler:
866871
867872 'multiTenancy.handler' => function ($operation, $tableName) {
868873 return ['customer_id' => 12];
@@ -871,9 +876,21 @@ If your tenants are identified by the "customer_id" column you can use the follo
871876This construct adds a filter requiring "customer_id" to be "12" to every operation (except for "create").
872877It also sets the column "customer_id" on "create" to "12" and removes the column from any other write operation.
873878
879+ NB: You may want to retrieve the customer id from the session (the "$_ SESSION" variable).
880+
874881#### Reconnect middleware
875882
883+ You may use the "reconnect" middleware when you have a separate database for each tenant.
884+ If the tenant has it's own database named "customer_12", then you can use the following handler:
885+
886+ 'reconnect.databaseHandler' => function () {
887+ return 'customer_12';
888+ },
889+
890+ This will make the API reconnect to the database specifying "customer_12" as the database name. If you don't want
891+ to use the same credentials, then you should also implement the "usernameHandler" and "passwordHandler".
876892
893+ NB: You may want to retrieve the database name from the session (the "$_ SESSION" variable).
877894
878895### Prevent database scraping
879896
0 commit comments