我想在我的产品实体和我的提供者实体之间实现连接,但是,一切似乎都没问题,但它不起作用..
我的错误:无法解析列的类型" id"类" AppBundle \ Entity \ Colombus \ Provider"
无法解析列的类型" id"类" AppBundle \ Entity \ Columbus \ Provider" 以下是Product实体的映射:
<?php
namespace AppBundle\Entity\Colombus;
use Doctrine\ORM\Mapping as ORM;
/**
* Product
*
* @ORM\Table(name="product")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository")
*/
class Product
{
/**
* @var int
*
* @ORM\Column(name="reference_produit", type="integer")
* @ORM\Id
*/
private $id;
/**
* @var string
*
* @ORM\ManyToOne(targetEntity="Provider")
* @ORM\JoinColumn(name="code_fournisseur_principal", referencedColumnName="id")
*/
private $provider;
提供者实体的映射:我省略了其他属性:
<?php
namespace AppBundle\Entity\Colombus;
use Doctrine\ORM\Mapping as ORM;
/**
* Provider
*
* @ORM\Table(name="provider")
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProviderRepository")
*/
class Provider
{
/**
* @var int
*
* @ORM\Column(name="code_fournisseur", type="string")
* @ORM\Id
*/
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('AppBundle\Entity\Colombus\Product')->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;
}
答案 0 :(得分:1)
您需要更正referencedColumnName
实体中的Product
/**
* @var string
*
* @ORM\ManyToOne(targetEntity="Provider")
* @ORM\JoinColumn(name="code_fournisseur_principal", referencedColumnName="code_fournisseur")
*/
private $provider;
但是我有意识到你正在尝试将code_fournisseur
的字符串类型列Provider
与未设置为auto
的字符串类型列或主键关联,这可能会给您带来另一个错误与您的映射相关