Symfony+Propel: use multiple schemas in a single project
Translation of the original in Catalan. Read it in: CatalàCastellano
The idea pursued when using multiple schemas in a single project is to be able to use multiple databases in a single project. The idea seems very simple, but through the official documentation of the Symfony project the truth is that I haven't been able to find the solution. In the explanation to carry out this functionality I'll refer the whole time to the .yml files and not to the equivalent .xml ones, but I suppose the idea is totally exportable.
It's about stopping using the schemal.yml file and starting to use different files called nomarbitrari_schema.yml, if instead of a name you want to use a number there are no problems in doing so either, for example, 1_schema.yml and successive ones.
As for the content of these files it's the usual one, although I'd recommend using small helpers like this one:
nombasededades:
_attributes:
package: lib.model.nombasededades
We'll use this nombasededades later to specify the connection data in the databases.yml file, but maybe the most interesting thing is to look at the package parameter which allows the whole data model to be kept inside lib/model/nombasedades. That is, everything ends up much better organized and easy to access.
You have to watch out if two databases have two tables with the same name, since if that happens then there'll be a conflict in the data models that are generated, because these will have the same name. That's easily solvable simply in the schema you have to tell it that the name of the class that represents the data of that database table is a different name from the table's, that is, the name chosen by default.
As for the databases.yml file its content is the usual one, you simply have to bear in mind that you need to describe the connection of each of the databases you have been declaring in the different schema.yml files, an example:
all:
nombasededades1:
class: sfPropelDatabase
param:
...
nombasededades2:
class: sfPropelDatabase
param:
...
Once all this is well configured we can already do a typical symfony propel-build-model and that's it.