The issue seems to be that no matter what connection is specified,
once the model is used, it will always try to use the last connection
in the list. Here's what I did.
I created two databases quickly:
CREATE DATABASE test1;
CREATE TABLE IF NOT EXISTS Rebel (
RebelID int(11) NOT NULL auto_increment,
RebelName varchar(32) NOT NULL,
BallOrChain tinyint(4) NOT NULL,
PRIMARY KEY (RebelID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE DATABASE test2;
CREATE TABLE IF NOT EXISTS Song (
Sacred int(11) NOT NULL,
Heart varchar(32) NOT NULL,
UNIQUE KEY Sacred (Sacred)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
I then configured the databases in sf:
./symfony configure:database --name=test1 --class=sfDoctrineDatabase
"mysql:host=localhost;dbname=test1" test1 test1
./symfony configure:database --name=test2 --class=sfDoctrineDatabase
"mysql:host=localhost;dbname=test2" test2 test2
$ cat config/databases.yml
all:
test1:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=test1'
username: test1
password: test1
test2:
class: sfDoctrineDatabase
param:
dsn: 'mysql:host=localhost;dbname=test2'
username: test2
password: test2
Then I ran all the normal things:
./symfony doctrine:build-schema
./symfony doctrine:build-model
./symfony doctrine:build-form
./symfony doctrine:build-filters
./symfony doctrine:generate-module --with-show --non-verbose-templates
frontend rebel rebel
./symfony doctrine:generate-module --with-show --non-verbose-templates
frontend song song
Verified that the model created correctly with the connection
specified in base:
$ head lib/model/doctrine/base/BaseRebel.class.php
<?php
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('Rebel', 'test1');
Now if I go to http://test.localhost/frontend_dev.php/rebel, I get an
error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'test2.Rebel' doesn't exist. Failing Query: "SELECT r.rebelid AS
rrebelid, r.rebelname AS rrebelname, r.ballorchain AS
rballorchain FROM Rebel r"
From this I see that it's still trying to use the test2 connection
even though everything is telling it to go to db test1.
If I go to http://test.localhost/frontend_dev.php/song it uses the
correct connection (test2).