2017-11-20 14 views
1

私は、製品のエンティティと私のプロバイダのエンティティ間の結合を達成したいを解決できませんでした、だけで、すべては大丈夫そうですが、それは動作しません。..は、列の型のSymfony

私のミス:列の型を解決できませんでした。 「ID」クラスの「AppBundle \エンティティ\コロンブス\プロバイダー」

ここでProductエンティティのマッピングがある 「AppBundle \エンティティ\コロンバス\プロバイダー」クラスの欄「ID」のタイプを解決できませんでした:

<?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

プロバイダ:: idは「はあなたのマッピングに関連した別のエラーを与える可能性がありautoまたは主キーに設定されていない部分への参加に関する意識しています@ var int 'annotated、しかし' type = string '?おそらく問題ではないかもしれませんが、ちょっと混乱します。 –

答えて

1

あなたは

/** 
* @var string 
* 
* @ORM\ManyToOne(targetEntity="Provider") 
* @ORM\JoinColumn(name="code_fournisseur_principal", referencedColumnName="code_fournisseur") 
*/ 
private $provider; 
のようなあなたの referencedColumnName Product内のエンティティを修正する必要があります

は、しかし、私はあなたがProviderの文字列型の列code_fournisseurを関連付けるしようとしているとそのはあなたに