2012-09-08 84 views
2

我有三個實體:類學說 COMMON 收藏 ArrayCollection的是不是一個有效的實體或映射超類

FeatureValue.php

<?php 

namespace Webmuch\ProductBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity 
*/ 
class FeatureValue 
{ 
/** 
* @ORM\Id 
* @ORM\Column(type="integer") 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 

/** 
* @ORM\Column(type="string", length="100") 
*/ 
protected $name; 

/** 
* @ORM\OneToMany(targetEntity="FeatureType", mappedBy="name") 
*/ 
private $featuretype; 



public function __construct() 
{ 
    $this->featuretype = new \Doctrine\Common\Collections\ArrayCollection(); 
} 

FeatureType.php

<?php 

namespace Webmuch\ProductBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Webmuch\ProductBundle\Entity\FeatureValue; 

/** 
* @ORM\Entity 
*/ 
class FeatureType 
{ 
/** 
* @ORM\Id 
* @ORM\Column(type="integer") 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 

/** 
* @ORM\Column(type="string", length=255, nullable=true) 
*/ 
protected $title; 

/** 
* @ORM\ManyToOne(targetEntity="FeatureValue", inversedBy="featuretype",cascade={"persist"}) 
* @ORM\JoinColumn(name="feature_value_id", referencedColumnName="id") 
*/  
protected $name; 

public function __construct() 
{ 
    $this->name = new \Doctrine\Common\Collections\ArrayCollection(); 
} 

產品.php

<?php 
namespace Webmuch\ProductBundle\Entity; 

use Gedmo\Mapping\Annotation as Gedmo; 
use Doctrine\ORM\Mapping as ORM; 
use Doctrine\Common\Collections\ArrayCollection as ArrayCollection; 

/** 
* @ORM\Entity 
* @ORM\Table() 
* @ORM\HasLifecycleCallbacks 
*/ 
class Product 
{ 
/** 
* @ORM\Id 
* @ORM\Column(type="integer") 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
protected $id; 

/** 
* @ORM\ManyToMany(targetEntity="Store") 
*/ 
protected $store; 

/** 
* @ORM\ManyToMany(targetEntity="Webmuch\CategoryBundle\Entity\Category") 
*/ 
protected $category; 

/** 
* @Gedmo\Sluggable 
* @ORM\Column(type="string", length=255) 
*/ 
protected $title; 

/** 
* @Gedmo\Slug(updatable=false, unique=true) 
* @ORM\Column(type="string", length=255) 
*/ 
protected $slug; 

/** 
* @ORM\Column(type="integer") 
*/ 
protected $quantity; 

/** 
* @ORM\Column(type="boolean") 
*/ 
protected $active; 

/** 
* @ORM\Column(type="text", length="4000", nullable="true") 
*/ 
protected $preview; 

/** 
* @ORM\ManyToMany(targetEntity="FeatureType") 
* @ORM\JoinColumn(name="feature_type_id", referencedColumnName="id") 
*/ 
protected $features; 

public function __toString() 
{ 
    return $this->getTitle(); 
} 

} 

我的問題是,當我在FeatureType中添加FeatureValue,然後顯示錯誤類「Doctrine \ Common \ Collections \ ArrayCollection不是有效的實體或映射的超類。」

在我的項目中,我希望FeatureType和我的產品實體中的FeatureValue一起使用。

假設在FeatureType中有兩個屬性Size和Colour.Now在FeatureType Size-三FeatueValue Small,Medium,Large已經給出,並且還假設在FeatureType Colour-三FeatureValue紅色,綠色,Yello已被給出。 現在我想在我的產品實體中同時顯示FeatureType和FeatureValue。

所以任何一個告訴我怎麼可以做。我已經嘗試了很多,但沒有成功。

回答

4

Webmuch\ProductBundle\Entity\FeatureType::__construct您指定ArrayCollection$this->name,這是錯誤的,因爲這是一個ToOne而不是ToMany。

只要刪除這一行。

相關問題