【问题标题】:Symfony 3.3 Schema Validation ErrorSymfony 3.3 模式验证错误
【发布时间】:2017-11-12 19:38:59
【问题描述】:

我有两个实体如下:

<?php
// src/coreBundle/Entity/model.php
namespace coreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use coreBundle\Entity\brand;

/**
*@ORM\Entity
*@ORM\Table(name="model")
*/
class model
{
    /**
    * @ORM\ManyToOne(targetEntity="coreBundle\Entity\brand", inversedBy="models")
    * @ORM\JoinColumn(name="brand_id", referencedColumnName="id")
    */
    private $brands;


    /**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
    public $id;

/**
    *@ORM\Column(type="integer")
    */
    public $brand_id;


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

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

    /**
    *@ORM\Column(type="string", length=200)
    */
    private $comment;

    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set brandId
     *
     * @param integer $brandId
     *
     * @return model
     */
    public function setBrandId($brandId)
    {
        $this->brand_id = $brandId;

        return $this;
    }

    /**
     * Get brandId
     *
     * @return integer
     */
    public function getBrandId()
    {
        return $this->brand_id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return model
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set imageUrl
     *
     * @param string $imageUrl
     *
     * @return model
     */
    public function setImageUrl($imageUrl)
    {
        $this->image_url = $imageUrl;

        return $this;
    }

    /**
     * Get imageUrl
     *
     * @return string
     */
    public function getImageUrl()
    {
        return $this->image_url;
    }

    /**
     * Set comment
     *
     * @param string $comment
     *
     * @return model
     */
    public function setComment($comment)
    {
        $this->comment = $comment;

        return $this;
    }

    /**
     * Get comment
     *
     * @return string
     */
    public function getComment()
    {
        return $this->comment;
    }



    /**
     * Set brands
     *
     * @param \coreBundle\Entity\brand $brands
     *
     * @return model
     */
    public function setBrands(\coreBundle\Entity\brand $brands = null)
    {
        $this->brands = $brands;

        return $this;
    }

    /**
     * Get brands
     *
     * @return \coreBundle\Entity\brand
     */
    public function getBrands()
    {
        return $this->brands;
    }
}

第二个如下:

<?php
// src/coreBundle/Entity/brand.php
namespace coreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use coreBundle\Entity\model;
use Doctrine\Common\Collections\ArrayCollection;

/**
*@ORM\Entity
*@ORM\Table(name="brand")
*/
class brand
{
    /**
     * ORM\OneToMany(targetEntity="coreBundle\Entity\model", mappedBy="brands")
     */
    private $models;
    public function __construct()
    {
        $this->models = new ArrayCollection();
    }

    /**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
public $id;

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



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return brand
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}

“model”与“brand”具有多对一关系

我遇到了架构验证问题,

*关联coreBundle\Entity\model#brands是指不存在的反边字段coreBundle\Entity\brand#models

你能告诉我我做错了什么吗,提前谢谢。

【问题讨论】:

    标签: php symfony doctrine schema


    【解决方案1】:

    如果您在 3 小时的痛苦之后仍然想知道,您错过了 @ORM\OneToMany 中的 @ (brand.php)

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2018-10-22
    • 2015-01-16
    • 1970-01-01
    • 2020-03-03
    • 2018-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-09-30
    相关资源
    最近更新 更多