类Doctrine\Common\Collections\ArrayCollection不是有效的实体或映射的超类 [英] Class Doctrine\Common\Collections\ArrayCollection is not a valid entity or mapped super class

查看:103
本文介绍了类Doctrine\Common\Collections\ArrayCollection不是有效的实体或映射的超类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个实体:

FeatureValue.php

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

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();
}

Product.php

Product.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不是有效的实体或映射的超类。

My problem is that when i add FeatureValue in FeatureType then show me error Class "Doctrine\Common\Collections\ArrayCollection is not a valid entity or mapped super class."

在我的项目中,我想要

假设在FeatureType中有两个属性Size和Colour。现在在FeatureType中有两个FeatueValue Small,Medium,Large,并且假设在FeatureType颜色中-给出了三个FeatureValue红色,绿色,黄色。
现在我想在我的产品实体中同时显示FeatureType及其FeatureValue。

suppose in FeatureType two property Size and Colour.Now in FeatureType Size- Three FeatueValue Small,Medium,Large have been given and also suppose in FeatureType Colour- Three FeatureValue Red,Green,Yello have been given. Now i want to show both the FeatureType along with their FeatureValue in my Product Entity.

所以任何人都告诉我该怎么做。很多,但没有成功。

So any one tell me how it can be done.I have tried a lot of but not succeed.

推荐答案

Webmuch\ProductBundle\Entity\FeatureType中: :__ construct 您将 ArrayCollection 分配给 $ this-> name ,这是错误的,因为这是ToOne而不是ToMany。

In Webmuch\ProductBundle\Entity\FeatureType::__construct you assign an ArrayCollection to $this->name, this is wrong, as this is a ToOne and not a ToMany.

只需删除此行即可。

这篇关于类Doctrine\Common\Collections\ArrayCollection不是有效的实体或映射的超类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆