2012-09-08 4 views
2

되지 않습니다 :클래스 교리 공통 모음 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이 유효한 엔티티 또는 매핑 된 수퍼 클래스가 아닙니다."라는 클래스 오류를 표시하는 것입니다.

내 프로젝트에서 FeatureValue와 함께 ProductType 엔티티를 원합니다.

FeatureType의 두 가지 속성 Size 및 Colour.Now가 FeatureType Size- Three FeatueValue Small, Medium, Large로 주어졌으며 FeatureType Colour- Three FeatureValue Red, Green, Yello가 주어 졌다고 가정합니다. 이제 FeatureType과 함께 FeatureType을 내 제품 엔터티에 표시하려고합니다.

아무도 나에게 어떻게 할 수 있는지 말해줘. 나는 많이 시도했지만 성공하지 못했다.

답변

4

Webmuch\ProductBundle\Entity\FeatureType::__construct에서을 $this->name으로 지정합니다. ToMne이 아니고 ToMany이기 때문에 잘못되었습니다.

이 줄을 삭제하면됩니다.

관련 문제