Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PropelORM v1 multiple databases

Tags:

php

propel

I have few problems with setting PropelORM to work with multiple databases. I couldn't find anything useful in the documentation.

  1. Generating schemas from multiple databases

    I prefer to make a change to database schema first and then run

    $ propel-gen . reverse
    

    to get schema.xml. What if my system consists of more then one database? Can it generate multiple schemas? I know from the documentation buildtime-conf.xml has to be created but it doesn't do anything for me.

  2. Generating classes

    Let's say I created to different schemas blog.schema.xml and platform.schema.xml. Is it possible to:

    1. have a different class prefix for each schema? In build.properties I can set propel.classPrefix but that will work globally for each schema.

    2. have a different project name for each schema? Again in the build.properties I can set propel.project and that will create a certain directory in classes directory. Right now all classes will go to the same place. If I will use the same table name in both schemas one class will overwrite the other.

The solution I can come on my own is to have a 2 different directories setup for a certain database however I would prefer more elegant solution.

like image 409
Lukasz Kujawa Avatar asked Nov 30 '12 15:11

Lukasz Kujawa


1 Answers

Can you post the <database> line from your Schema?

As long as you have the following:

<database package="blog" name="blog" defaultIdMethod="native">

Inside of your blog.schema.xml it should generate a new directory for you. If you let propel lazyload those for you though, you are right you'll get collisions, so I just manually pre-pended something to my tables in the schema.xml (which might not be the most efficient thing to handle things).

But you can do something like:

  1. in blog.schema.xml:

     <table name="users" phpName="blogUsers" idMethod="native">
    
  2. in platform.schema.xml:

     <table name="users" phpName="platformUsers" idMethod="native">
    

That worked fine for me.

like image 77
DaOgre Avatar answered Sep 19 '22 15:09

DaOgre