1
votes

Here function is overriding on based framework called by name Sonata which is building admin template :

protected function configureFormFields(FormMapper $formMapper){
$formMapper->add('owner', 'sonata_type_model_list',
    array(
        'class' => 'XYZXBundle:ContestUser',
        'btn_add'       => false,      //Specify a custom label
        'btn_list'      => 'Search',     //which will be translated
        'btn_delete'    => false,             //or hide the button.
        'btn_catalogue' => 'SonataNewsBundle', //Custom translation domain for buttons
    ), array(
        'placeholder' => 'No owner selected'
    ))
    }

Object structure:

/**
 * @ORM\ManyToOne(targetEntity="XYZ\XBundle\Entity\ContestUser")
 * @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
 * @var XYZ\XBundle\Entity\ContestUser
 */
protected $owner;

Happens when i tried to insert new row.

Error stacktrace:

Expected argument of type "XYZ\XBundle\Entity\XYZ\XBundle\Entity\ContestUser", "XYZ\XBundle\Entity\ContestUser" given` in vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php at line 254

UPDATE 1

I tried to use like that below, but still causes the same error.

 * @ORM\ManyToOne(targetEntity="\XYZ\XBundle\Entity\ContestUser")
 or
 * @ORM\ManyToOne(targetEntity="ContestUser")

UPDATE 2

file XYZ\X\Entity\Contest.php

<?php

namespace XYZ\XBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Filesystem\Filesystem;

/**
 * XYZ\XBundle\Entity\Contest
 *
 * @ORM\Table(name="contests")
 * @ORM\Entity(repositoryClass="XYZ\XBundle\Entity\ListRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Contest

XYZ\X\Entity\ContestUser.php

<?php

namespace XYZ\XBundle\Entity;

use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContext;
use Symfony\Component\Filesystem\Filesystem;

/**
 * @ORM\Entity()
 * @ORM\Table(name="contest_users")
 */
class ContestUser extends BaseUser
{

Namespaces are still valid ok, but only with type sonata_type_model_list causes this error.

2
targetEntity="ContestUser"malcolm
@malcolm, that doesnt workmachei

2 Answers

0
votes

You have incorrect namespace in your mapping annotation in line:

* @ORM\ManyToOne(targetEntity="XYZ\XBundle\Entity\ContestUser")

It means a namespace relative to the current one.

You should either add a backslash at the beginning to make it an absolute namespace.

* @ORM\ManyToOne(targetEntity="\XYZ\XBundle\Entity\ContestUser")

or use simply only class name as both current and ContestUser classes seem to be in the same namespace:

* @ORM\ManyToOne(targetEntity="ContestUser")
0
votes

I found stupid my fail and i had:

public function setOwner(XYZ\XBundle\Entity\ContestUser $owner){} 

that code works for me:

public function setOwner(\XYZ\XBundle\Entity\ContestUser $owner){}