Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Database and Entity settings: Neither property ... nor method ...nor method ... exists in class

I have an Symfony2 project cnnected to the database. For each table I have an entity.

Now, I am trying to connect one Entity with another using ManyToOne.

Here is the problem:

I have Two entitys: User and Workplace.

In the User Entity, I have:

 /**
 * @ORM\ManyToOne(targetEntity="Workplace")
 * @ORM\JoinColumn(name="workplace", referencedColumnName="place")
 **/
protected $workplace;

/**
 * Set workplace
 *
 * @param integer $workplace
 */
public function setWorkplace($workplace)
{
    $this->workplace = $workplace;
}

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

In the Workplace Entity I have:

/**
 * @ORM\Column(type="text")
 */
protected $place;



/**
 * Set place
 *
 * @param text $place
 */
public function setPlace($place)
{
    $this->place = $place;
}

/**
 * Get place
 *
 * @return text 
 */
public function getPlace()
{
    return $this->place;
}

And with that, I am getting an exception:

Neither property "workplace" nor method "getWorkplace()" nor method "isWorkplace()" exists in class "SciForum\Version2Bundle\Entity\Workplace" 

How could this be resolved. Thank you very much.

like image 283
Milos Cuculovic Avatar asked Dec 21 '22 15:12

Milos Cuculovic


1 Answers

Try this

->add('place','entity',  array('class'=>'yourBundle:WorkPlace',
                               'property'=>'place'))

in your form Type.

like image 100
Asish AP Avatar answered May 10 '23 01:05

Asish AP