Orm 原则2“;在关联上找到类型为的实体,但应为“;

Orm 原则2“;在关联上找到类型为的实体,但应为“;,orm,doctrine-orm,zend-framework2,Orm,Doctrine Orm,Zend Framework2,与ZF2和条令2合作。正在尝试使用实体管理器插入数据 我有这个实体: class Link { /** * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") */ protected $link_id; /** @ORM\Column(type="string", length=255, nullable=false) */ p

与ZF2和条令2合作。正在尝试使用实体管理器插入数据

我有这个实体:

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

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

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

    /** @ORM\Column(columnDefinition="LONGTEXT NOT NULL") */
    protected $description;

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

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

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

    /** @ORM\Column(type="datetime", columnDefinition="DATETIME NOT NULL") */
    protected $date_created;

    /**
     * @ORM\ManyToOne(targetEntity="Schema\Entity\Category")
     **/
    private $category_id;

    public function __get($property) {
        if (property_exists($this, $property)) {
              return $this->$property;
        }
    }

    public function __set($property, $value) {
        if (property_exists($this, $property)) {
            $this->$property = $value;
        }
        return $this;
    }
 }
而这

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

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

    public function __get($property) {
        if (property_exists($this, $property)) {
              return $this->$property;
        }
    }

    public function __set($property, $value) {
        if (property_exists($this, $property)) {
            $this->$property = $value;
        }
        return $this;
    }
}
当我尝试此选项时:

$link = new Link();
$link->title = 'aa';
$link->category_id = array('1');
$link->link_type_id = array('1');
$link->description = 'adsfa';
$link->webpage_url = 'asdfad';
$link->short_description = 'aa';
$link->email = 'asdf';
$link->meta_keys = 'asdf';
$link->date_created ='2014-01-14 13:26:54';


$this->getObjectManager()->persist($link); // ?????
$this->getObjectManager()->flush();
给出错误:在关联Schema\entity\Link\category\u id上找到类型为的实体,但应为Schema\entity\category

我还尝试将cascade={“persist”}放在注释中,但出现错误:类“”不存在


为什么?

您必须将category\u id设置为
Schema\Entity\category[]
的值,而不是
array()

有点混乱。我该怎么做?我只想将value=1与其他字符串数据一起传递给
链接
实体。你是对的,我意识到我不知道数据库关联真正做什么。。。去学习。谢谢