tags:

views:

1231

answers:

4

I am using Propel as my DAL for my Symfony project. I can't seem to get my application to work across two or more databases.

Here's my schema.yml:

db1:
  lkp_User:
    pk_User:                     { type: integer, required: true, primaryKey: true, autoIncrement: true }
    UserName:                    { type: varchar(45), required: true }
    Password:                    longvarchar
    _uniques:
      Unique:                    [ UserName ]

db2:
  tesco:
    Id:                  { type: integer, required: true, primaryKey: true, autoIncrement: true }
    Name:                { type: varchar(45), required: true }
    Description:         longvarchar

And here's the databases.yml:

dev:
  db1:
    param:
      classname: DebugPDO
test:
  db1:
    param:
      classname: DebugPDO
all:
  db1:
    class: sfPropelDatabase
    param:
      classname: PropelPDO
      dsn: 'mysql:dbname=bpodb;host=localhost'   #where the db is located
      username: root
      password: #pass
      encoding: utf8
      persistent: true
      pooling: true


  db2:
    class: sfPropelDatabase
    param:
      classname: PropelPDO
      dsn: 'mysql:dbname=mystore2;host=localhost'   #where the db is located
      username: root
      password: #pass
      encoding: utf8
      persistent: true
      pooling: true

When I call php symfony propel-build-model, only db1 is generated, db2 is not.

Any idea how to fix this problem?

+2  A: 

I got this issue working! The most important thing is you must name your schema according to %dbname%.schema.yml. In this way Symfony will be able to assign the ymls to the correct database.

Ngu Soon Hui
That's bad ass. Thanks for the tip!
mattsidesinger
+1  A: 

Also when running the task you should specify the connection for example:

symfony propel:build-all-load --connection=my_connection

This worked for me, hope it helps.

Hello, I tried your suggestion--- but doesn't work..
Ngu Soon Hui
+1  A: 

You can also use Propel::getConnection('db2') to manually retrieve a connection.

Just have in mind that what you call "db1", "db2" are the connection names. You can have several connections to a same database with various login/permissions (like read only etc.).

It's very good for testing purpose: you can do it with the same connection name with a different database. No way to crash your production database with that :)

Oncle Tom
A: 

This is a great answer, I am doing the same thing but trying to use Propel 1.5 with 3 DBs. When you define your Schemas do you have to define all the tables in each DB or just the ones you plan to use. Also do you have to define all the columns per table or just the ones you need?

Shadley