实体中未定义属性或方法


Property or method not defined in entity

我有一个Usuario实体定义如下:

namespace Checkengine'DashboardBundle'Entity;
use Doctrine'ORM'Mapping as ORM;
use Doctrine'Common'Collections'ArrayCollection;
use Symfony'Component'Validator'Constraints as Assert;
use Symfony'Bridge'Doctrine'Validator'Constraints'UniqueEntity;
use Symfony'Component'Security'Core'User'UserInterface;
use Symfony'Component'HttpFoundation'File'UploadedFile;
use JMS'Serializer'Annotation as Serializer;
/**
 * Usuario.
 *
 * @ORM'Table(name="usuarios")
 * @ORM'Entity(repositoryClass="Checkengine'DashboardBundle'Repository'UsuarioRepository")
 * @ORM'HasLifecycleCallbacks()
 * @UniqueEntity("email")
 *
 * @Serializer'ExclusionPolicy("all")
 */
class Usuario implements UserInterface, 'Serializable
{
    ...
    /**
     * @var integer
     *
     * @todo No recibir ofertas del usuario.
     *
     * @ORM'ManyToMany(targetEntity="Checkengine'DashboardBundle'Entity'Empresa")
     * @ORM'JoinTable(name="no_ofertas",
     *      joinColumns={@ORM'JoinColumn(name="usuario_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM'JoinColumn(name="empresa_id", referencedColumnName="id")}
     * )
     *
     * @Serializer'Expose
     * @Serializer'Type("ArrayCollection<Checkengine'DashboardBundle'Entity'Empresa>")
     * @Serializer'MaxDepth(1)
     */
    private $noOfertas;
    ...
    public function __construct()
    {
        $this->noOfertas = new ArrayCollection();
    }
    ...
    /**
     * Add noOfertas.
     * @param 'Checkengine'DashboardBundle'Entity'Empresa $noOfertas
     * @return Usuario
     */
    public function addNoOfertas(Empresa $noOfertas)
    {
        $this->noOfertas[] = $noOfertas;
        return $this;
    }
    /**
     * Remove noOfertas.
     * @param 'Checkengine'DashboardBundle'Entity'Empresa $noOfertas
     */
    public function removeNoOfertas(Empresa $noOfertas)
    {
        $this->noOfertas->removeElement($noOfertas);
    }
    /**
     * Get noOfertas.
     * @return 'Doctrine'Common'Collections'Collection
     */
    public function getNoOfertas()
    {
        return $this->noOfertas;
    }
}

每当我尝试更新Usuario时,我都会收到以下错误:

既不是属性"noOfertas",也不是其中一个方法"addNoOferta()"/"removeNoOferta,类中存在"__set()"或"__call()"并具有公共访问权限"Checkengine''DashboardBundle''Entity''Usuario"。

这是updateAction()方法:

public function updateAction(Request $request, $id)
{
    $em = $this->getDoctrine()->getManager();
    $entity = $em->getRepository('DashboardBundle:Usuario')->find($id);
    if (!$entity) {
        throw $this->createNotFoundException('Unable to find Usuario entity.');
    }
    $deleteForm = $this->createDeleteForm($id);
    $editForm = $this->createEditForm($entity);
    $current_pass = $entity->getPassword();
    $editForm->handleRequest($request);
    if ($editForm->isValid()) {
        if (null == $entity->getPassword()) {
            $entity->setPassword($current_pass);
        } else {
            $this->setSecurePassword($entity);
        }
        $em->flush();
        return $this->redirect($this->generateUrl('usuarios_edit', array('id' => $id)));
    }
    return array(
        'entity'      => $entity,
        'form'        => $editForm->createView(),
        'delete_form' => $deleteForm->createView(),
    );
}

那里可能出了什么问题?我缺少什么?我已经清理了好几次缓存,还重新启动了Web服务器(以防万一),但仍然没有任何问题,这让我抓狂,有什么建议吗?线索

如错误消息所示,您需要添加/删除一个$noOferta对象,而不是整个集合$noOfertas

你需要重写这样的方法:

public function addNoOferta(Empresa $noOferta)
{
    $this->noOfertas[] = $noOferta;
    return $this;
}
public function removeNoOferta(Empresa $noOferta)
{
    $this->noOfertas->removeElement($noOferta);
}