Using Symfony-2.1 and Doctrine-2.3. I have multiple databases and need to do cross-database joins so I followed the suggestions in:
- Multiple database connection in Doctrine2 and Zend framework
- Using Relationships with Multiple Entity Managers
and set up multiple connections and one entity manager. Here is app/config/config.yml
:
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: pdo_mysql
host: 127.0.0.1
dbname: db1
db2:
driver: pdo_mysql
host: 127.0.0.1
dbname: db2
orm:
default_entity_manager: default
auto_generate_proxy_classes: %kernel.debug%
entity_managers:
default:
auto_mapping: true
mappings:
FirstBundle:
type: annotation
dir: Model
prefix: NoiseLabs\FirstBundle\Model
SecondBundle:
type: annotation
dir: Model
prefix: NoiseLabs\SecondBundle\Model
Entity class in FirstBundle
:
namespace NoiseLabs\FirstBundle\Model;
/**
* @ORM\Entity
* @ORM\Table(name="db1.table1")
*/
class FirstEntity
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
Entity class in SecondBundle
:
namespace NoiseLabs\SecondBundle\Model;
/**
* @ORM\Entity
* @ORM\Table(name="db2.table2")
*/
class SecondEntity
{
/**
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="NoiseLabs\FirstBundle\Model\FirstEntity")
* @ORM\JoinColumn(name="firstId", referencedColumnName="id", onDelete="CASCADE")
*/
protected $first;
}
Now, the problem is app/console doctrine:schema:update --dump-sql
only detects schema changes in (default connection) db1.tables
. If I set the default connection to db2
it will only output sql related to db2.tables
.
I've checked with app/console doctrine:mapping:info
and all entity classes are being mapped.
Is this a limitation of Doctrine/Symfony or do I need to adjust my configuration? Thanks.