我想在我的产品实体和我的提供者实体之间实现连接,只是,一切似乎都很好,但它不起作用..
我的错误:无法解析类"AppBundle\实体\Colombus\Provider"的列"id"的类型
无法解析类"AppBundle \ 实体 \ 哥伦布 \ 提供程序"的列"id"的类型下面是产品实体的映射:
<?php
namespace AppBundleEntityColombus;
use DoctrineORMMapping as ORM;
/**
* Product
*
* @ORMTable(name="product")
* @ORMEntity(repositoryClass="AppBundleRepositoryProductRepository")
*/
class Product
{
/**
* @var int
*
* @ORMColumn(name="reference_produit", type="integer")
* @ORMId
*/
private $id;
/**
* @var string
*
* @ORMManyToOne(targetEntity="Provider")
* @ORMJoinColumn(name="code_fournisseur_principal", referencedColumnName="id")
*/
private $provider;
提供者实体的映射:我省去了其他属性:
<?php
namespace AppBundleEntityColombus;
use DoctrineORMMapping as ORM;
/**
* Provider
*
* @ORMTable(name="provider")
* @ORMEntity(repositoryClass="AppBundleRepositoryProviderRepository")
*/
class Provider
{
/**
* @var int
*
* @ORMColumn(name="code_fournisseur", type="string")
* @ORMId
*/
private $id;
控制器:
/**
*
* @Route("/{_locale}/build_order/step1/2", name="order.build")
* @return Response
*/
public function buildOrderAction(SessionInterface $session){
$em = $this->getManager($session->get('em'));
$products = $em->getRepository('AppBundleEntityColombusProduct')->findAll();
return $this->render('AppBundle::creation/create_order.html.twig',[
'products' => $products
]);
}
如果它也可以帮助您:
public function getManager($dbname){
$paths = array(__DIR__ . '/AppBundle/Entity/Colombus');
$isDevMode = false;
$conn = array(
'dbname' => $dbname,
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',
'charset' => 'utf8',
);
$config = Setup::createConfiguration($isDevMode);
$driver = new AnnotationDriver(new AnnotationReader(), $paths);
AnnotationRegistry::registerLoader('class_exists');
$config->setMetadataDriverImpl($driver);
$em = EntityManager::create($conn, $config);
return $em;
}
您需要更正Product
实体中的referencedColumnName
,例如
/**
* @var string
*
* @ORMManyToOne(targetEntity="Provider")
* @ORMJoinColumn(name="code_fournisseur_principal", referencedColumnName="code_fournisseur")
*/
private $provider;
但是我意识到您尝试将字符串类型列code_fournisseur
Provider
相关联的连接部分,并且未设置为auto
或主键,这可能会给您带来另一个与您的映射相关的错误