原则实体代理异常

Doctrine entity proxy exception

我的 Symfony 项目中的一个实体有一个大问题。

首先是一些代码: 地址实体

<?php
namespace AppBundle\Entity;
class Address
{
/**
* @var integer
*/
private $id;

/**
 * @var string
 */
private $street;

/**
 * @var string|null
 */
private $postalCode;

/**
 * @var string|null
 */
private $city;

/**
 * @var string|null
 */
private $province;

/**
 * @var float
 */
private $latitude;

/**
 * @var float
 */
private $longtitude;

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

/**
 * Set street
 *
 * @param string $street
 * @return Address
 */
public function setStreet($street)
{
    $this->street = $street;

    return $this;
}

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

/**
 * Set postalCode
 *
 * @param integer $postalCode
 * @return Address
 */
public function setPostalCode($postalCode)
{
    $this->postalCode = $postalCode;

    return $this;
}

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

/**
 * Set city
 *
 * @param string $city
 * @return Address
 */
public function setCity($city)
{
    $this->city = $city;

    return $this;
}

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

/**
 * Set province
 *
 * @param string $province
 * @return Address
 */
public function setProvince($province)
{
    $this->province = $province;

    return $this;
}

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

/**
 * Set latitude
 *
 * @param string $latitude
 * @return Address
 */
public function setLatitude($latitude)
{
    $this->latitude = $latitude;

    return $this;
}

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

/**
 * Set longtitude
 *
 * @param string $longtitude
 * @return Address
 */
public function setLongtitude($longtitude)
{
    $this->longtitude = $longtitude;

    return $this;
}

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

地址实体映射:

AppBundle\Entity\Address:
type: entity
table: addresses

id:
    id:
        type: integer
        generator:
            strategy: AUTO
fields:
    street:
        type: string
        nullable: false
    postalCode:
        name: postal_code
        type: string
        nullable: true
    city:
        type: string
        nullable: false
    province:
        type: string
        nullable: true
    latitude:
        type: decimal
        scale: 12
        precision: 18
        nullable: true
    longtitude:
        type: decimal
        scale: 12
        precision: 18
        nullable: true

场地实体映射: AppBundle\Entity\Venue(为了示例而缩短):

type: entity
table: venues
manyToOne:
    address:
        targetEntity: AppBundle\Entity\Address
        joinColumn:
            name: address_id
            referencedColumnName: id
        nullable: false
        cascade: ["persist"]

问题是我面临抛出的异常:

Notice: Array to string conversion 500 Internal Server Error - ContextErrorException here $proxyCode = strtr($this->proxyClassTemplate, $venueholders); (in vendor/doctrine/common/lib/Doctrine/Common/Proxy/ProxyGenerator.php at line 280).

当我删除关系时,一切正常,所以它告诉我地址​​实体存在某种问题。

我已经尝试清除缓存 - 没有成功。映射对我来说没问题,getters/setters 是正确的。

有什么建议吗?

尝试 column: 而不是 name:

postalCode:
        column: postal_code
        type: string
        nullable: true

您是否尝试过完全重新安装您的供应商?我在您的问题中看到了一个问题:$proxyCode = strtr($this->proxyClassTemplate, $venueholders);.

ProxyGenerator class 的第 280 行应该如下所示:https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Proxy/ProxyGenerator.php#L280.

您是否尝试过在您的代码中应用搜索和替换?