I try to develop a website using Symfony 2. I want to use 2 databases. One with general data (DB_DATA) and another with my application data (DB_APP). I've made two bundles "MyCompany\DataBundle" and "MyCompany\AppBundle".
In "MyCompany\DataBundle" I've declared an entity "Customer" which referes to the clients of my company. In "MyCompany\AppBundle" there is an Entity "Account" which is used by the application and must reference the Customer.
For now they look like this :
\src\MyCompany\DataBundle\Entity\Customer.php
<?php
namespace MyCompany\DataBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Customer
*
* @ORM\Table(name="customer")
* @ORM\Entity
*/
class Customer
{
/**
* @var integer
*
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="LASTNAME", type="string", length=255, nullable=false)
*/
private $lastName;
/**
* @var string
*
* @ORM\Column(name="FIRSTNAME", type="string", length=255, nullable=false)
*/
private $firstName;
...
}
\src\MyCompany\AppBundle\Entity\Account.php
<?php
namespace MyCompany\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Account
*
* @ORM\Table(name="account")
* @ORM\Entity
*/
class Account
{
/**
* @var integer
*
* @ORM\Column(name="ID", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
*
* @ORM\OneToOne(targetEntity="\MyCompany\DataBundle\Entity\Customer")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="CUSTOMER_ID", referencedColumnName="ID")
* })
*/
private $customer;
}
\app\config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
appdb:
driver: "%database_driver2%"
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AppBundle:
type: annotation
mapping: true
dir: "%kernel.root_dir%/../src/MyCompany/AppBundle/Entity/"
prefix: MyCompany\AppBundle\Entity\
is_bundle: false
alias: APP
app:
connection: appdb
mappings:
DataBundle:
type: annotation
mapping: true
dir: "%kernel.root_dir%/../src/MyCompany/DataBundle/Entity/"
prefix: MyCompany\DataBundle\Entity\
is_bundle: false
alias: DATA
Everytime I try to update schema, I get this error :
[Doctrine\Common\Persistence\Mapping\MappingException]
The class 'MyCompany\DataBundle\Entity\Customer' was not found in the chain configured namespaces MyCompany\AppBundle\Entity