我需要跨数据库关系,我已经读过这个但由于映射问题而无法得到我想要的。这是我的情况
namespace App\Entity\Utility;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Crm\User;
/**
* Description of Test
*
* @ORM\Table(name="fgel_utility.fgel_test")
* @ORM\Entity(repositoryClass="App\Repository\Utility\TestRepository")
*/
class Test
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
*
* @var User
*
* @ORM\ManyToOne(targetEntity="App\Entity\Crm\User")
* @ORM\JoinColumn(name="user_cod", referencedColumnName="AUCUT")
*/
protected $user = null;
public function getId()
{
return $this->id;
}
public function getUser(): User
{
return $this->user;
}
public function setId($id)
{
$this->id = $id;
return $this;
}
public function setUser(User $user)
{
$this->user = $utente;
return $this;
}
}
namespace App\Entity\Crm;
use Doctrine\ORM\Mapping as ORM;
/**
*
* @ORM\Table(name="crm.USER")
* @ORM\Entity(repositoryClass="App\Repository\FintelGasDati\AnuteRepository")
*/
class User
{
/**
*
* @ORM\Id
* @ORM\Column(name="AUCUT", type="integer", nullable=false)
*/
protected $codiceCliente;
# SOME CODE
}
我的学说.yaml
doctrine:
orm:
default_entity_manager: default
entity_managers:
#################################
# Update schema only with this em
#################################
default:
connection: mssql_1
mappings:
Utility:
type: "annotation"
# The directory for entity (relative to bundle path)
dir: '%kernel.project_dir%/src/Entity/Utility'
prefix: 'App\Entity\Utility'
alias: Utility
mssql_crm:
connection: mssql_1
mappings:
Crm:
type: "annotation"
# The directory for entity (relative to bundle path)
dir: '%kernel.project_dir%/src/Entity/Crm'
prefix: 'App\Entity\Crm'
alias: Crm
所以他们共享相同的连接(但不同的 em)。连接的用户有权读取/写入两个数据库(但只能将架构更改为 fgel_utility DB。两个 DB 都存储在 SQL Server 2008 中。当我尝试执行时
php bin/console doctrine:schema:update --dump-sql
我收到这个错误
在链配置的命名空间 App\Entity\Utility、FOS\UserBundle\Model 中找不到类“App\Entity\Crm\User”