I have a project which uses three different databases the first one is the main database which I can make changes to the second two belong to different projects but I need to access data in them. The following is a simplified directory structure.
Src
AppBundle
FoxBundle
Below are the files for the abstract class and interface for BusinessUnits the Vehicle and Driver are similar.
<?php
// src/AppBundle/Model/BusinessUnitInterface.php
namespace AppBundle\Model;
interface BusinessUnitInterface
{
/**
* @return string
*/
public function __toString();
}
The Abstract Class
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use FoxBundle\Entity\BusinessUnit as BaseBU;
use AppBundle\Model\BusinessUnitInterface;
/**
* @ORM\Entity
* @ORM\Table(name="business_unit_fox")
*/
class BusinessUnitFox extends BaseBU implements BusinessUnitInterface
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* {@inheritDoc}
* @see \AppBundle\Model\BusinessUnitInterface::__toString()
*/
public function __toString() {
return $this->getId();
}
}
config.yml
# Doctrine Configuration
doctrine:
dbal:
default_connection: maxdb
connections:
maxdb:
# ...
foxdb:
# ...
max2db:
# ...
orm:
resolve_target_entities:
AppBundle\Model\VehicleInterface: AppBundle\Entity\VehicleFox
AppBundle\Model\UDODriver: AppBundle\Entity\DriverMax
AppBundle\Model\BusinessUnit: AppBundle\Entity\BusinessUnitFox
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: maxem
entity_managers:
maxem:
connection: maxdb
mappings:
AppBundle:
BWTCalendarBundle: ~
BWTFMBundle: ~
BWTHealthCheckBundle: ~
BWTSkytrackBundle: ~
BWTTelematicsBundle: ~
foxem:
connection: foxdb
mappings:
FoxBundle: ~
max2em:
connection: max2db
mappings:
MaxBundle: ~
When I do A SQL call I get the following error
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'telematics.vehicle_fox' doesn't exist
So I ran doctrine:schema:update
and got the following error
[Doctrine\Common\Persistence\Mapping\MappingException] Class 'AppBundle\Model\BusinessUnitInterface' does not exist
Is there anything that I am missing?
Is it possible to declare a OneToMany relationship from the abstract class?
You forgot the Interface suffix for UDODriverInterface and BusinessUnitInterface. You can follow the Symfony doc to do your mapping on Abstract classes and Interfaces
resolve_target_entities:
AppBundle\Model\VehicleInterface: AppBundle\Entity\VehicleFox
AppBundle\Model\UDODriverInterface: AppBundle\Entity\DriverMax
AppBundle\Model\BusinessUnitInterface: AppBundle\Entity\BusinessUnitFox
Note also with the current declaration, your AppBundle\Entity\BusinessUnitFox class is not abstract.