![]() |
|
Snippets |
|
if you using multiple database from Propel, It can be solve by writing two or more schema files.
PROJECT_DIR/config/databases.yml
all:
database1:
class: sfPropelDatabase
param:
dsn: pgsql://foo:bar@hostname/database1
database2:
class: sfPropelDatabase
param:
dsn: mysql://foo:bar@hostname/database2
PROJECT_DIR/config/database1.schema.xml
<?xml version="1.0" encoding="UTF-8"?> <database name="database1" defaultIdMethod="native" noxsd="true"> <table name="foo" phpName="Foo"> .... </table> </database>
PROJECT_DIR/config/database2.schema.xml
<?xml version="1.0" encoding="UTF-8"?> <database name="database2" defaultIdMethod="native" noxsd="true"> <table name="bar" phpName="Bar"> .... </table> </database>
Last, build model command.
$ symfony propel-build-model
Build complete.
Example, getting multiple databases connection handler.
$database1_connection_handler = Propel::getConnection(FooPeer::DATABASE_NAME); $database2_connection_handler = Propel::getConnection(BarPeer::DATABASE_NAME);
Comments on this snippet
So, I was thinking about "outsourcing" my authentication and permission management into a second database, so that queries in a module can't afflict this sensible tables. But I can't figure where I have to put the things with the Propel::getConnection - in the Model? In the BaseModel? Or will symfony/propel handle this automatically with setting the correct connection in the model while propel builds it? I'm a bit ... confused ;)