Handling several Propel packages

When working on complex applications, it is mostly common to deal with several database connections. The main database is often built and adminstrated by yourself, but you sometimes need to handle external databases, probably with a read-only access.

Symfony and propel allows you to easily manage these ‘externals’ connections.

You can create several schema.xml that defines tables for each database.


Connection settings for several databases are handled by the databases.yml configuration file :

    class:          sfPropelDatabase
      dsn:          mysql://user:password@localhost/database
    class:          sfPropelDatabase
      dsn:          mysql://login:pass@hostname/external_db_name

Skipping sql code generation

As we only want to access the external database, we can skip the sql generation for the external schema. We only need model objects to read data from that database (and also create, update and delete in case of a full access database).

Propel allows you that by adding the “skipSql” attribute to a table. Refer to the Propel documentation for the complete list of available options.

<table name=“article” idMethod=“native” skipSql=“true”>

By doing such, no sql data will be generated. That way, you can still use propel tasks to automatically load your main database without creating the freshly built tables of the external database, which won’t be used.

Besides, external developers have now a clear view of what database has to be created and used directly, and what database stands has an external reference.

When lauching that task :

$ symfony propel:build-all-load

Only the main schema.xml will build and insert the corresponding sql code in your database.

Using package names

You can also define a name for each propel package that will specify the generated files output destination.

Default is “lib.model”, which referers to the lib/model directory.


<database name=“external” package=“lib.model.external”>

Model files will be generated in the lib/model/external sub-folder.

$ symfony propel:build-model
| |+om
| |+map
| |-Account.php
| `-AccountPeer.php

By declaring different package names, propel will build separate .sql files.

$ symfony propel:build-sql

will generate :

lib.model.schema.sql (containing tables defined in schema.xml)
lib.model.external.schema.sql (containing the external database tables)

Using a blank package name

You can also specify a “blank” name for a package. Model files will be generated under the default lib/model directory.

The pattern used for the .sql file generation is <package.name>.schema.sql. Therefore, a schema.sql will be created, even if every table of the schema are ‘sql skipped’.


  1. 1 rpsblog.com » A week of symfony #88 (1-&gt;7 september 2008)

    […] Handling several Propel packages […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: