Skip to content

Commit 8f37326

Browse files
authored
Merge pull request #234 from moufmouf/multidb_bundle_doc
Adding documentation to support several databases
2 parents eb256a3 + f7dedce commit 8f37326

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

doc/install_symfony.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,60 @@ class TestController extends Controller
104104
{
105105
return $this->json($this->userDao->findAll());
106106
}
107-
}```
107+
}
108+
```
109+
110+
### Supporting several databases
111+
<small>TDBM 5.2+</small>
112+
113+
It is possible to plug TDBM to several databases.
114+
In this case, you will first want to declare several database connections in DBAL.
115+
116+
For instance:
117+
118+
**config/packages/doctrine.yaml**
119+
```yaml
120+
doctrine:
121+
dbal:
122+
default_connection: default
123+
connections:
124+
default:
125+
# configure these for your database server
126+
url: '%env(resolve:DATABASE_URL)%'
127+
driver: 'pdo_mysql'
128+
server_version: '5.7'
129+
charset: utf8mb4
130+
customer:
131+
# configure these for your database server
132+
url: '%env(resolve:DATABASE_CUSTOMER_URL)%'
133+
driver: 'pdo_mysql'
134+
server_version: '5.7'
135+
charset: utf8mb4
136+
```
137+
138+
Then, in TDBM, you will use these connections.
139+
140+
**config/packages/tdbm.yaml**
141+
```yaml
142+
tdbm:
143+
databases:
144+
default:
145+
bean_namespace: App\Beans
146+
dao_namespace: App\Daos
147+
customer:
148+
connection: doctrine.dbal.customer_connection
149+
bean_namespace: App\Customer\Beans
150+
dao_namespace: App\Customer\Daos
151+
```
152+
153+
Notice how the "connection" key is pointing to the instance of DBAL connection you are targeting.
154+
155+
Now, when you want to generate beans and Daos, you will have to target the correct database:
156+
157+
```bash
158+
$ bin/console tdbm:generate # targets the default database
159+
$ bin/console tdbm:generate:customer # targets the "customer" database
160+
```
108161

109162
Next step
110163
---------

0 commit comments

Comments
 (0)