Question

I am trying to fetch an object from my database in symfony2 and doctrine using one of my entity classes and a repository class.

Here is the function call:

$game = $em->getRepository('MLBPBeerBundle:TableGame')->findBygameId($gid);
$game.setZoneTableid('20');

Here is a snippet of my repository class:

class TableGameRepository extends EntityRepository
{
public function findBygameId($gid)
{
    return $this->getEntityManager()
        ->createQuery('SELECT g FROM MLBPBeerBundle:TableGame g WHERE g.gameId = ' . $gid)
        ->getSingleResult();
}

And here is a snippet of my entity class:

/**
 * MLBP\BeerBundle\Entity\TableGame
 *
 * @ORM\Table(name="table_game")
 * @ORM\Entity(repositoryClass="MLBP\BeerBundle\Repository\TableGameRepository")
 * 
 */
class TableGame
{
    /**
     * @var TableTable
     *
     * @ORM\ManyToOne(targetEntity="TableTable")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="ZONE_TABLEID", referencedColumnName="TABLE_ID")
     * })
     */
        protected $zoneTableid;

    /**
     * Set zoneTableid
     *
     * @param MLBP\BeerBundle\Entity\TableTable $zoneTableid
     */
    public function setZoneTableid(\MLBP\BeerBundle\Entity\TableTable $zoneTableid)
    {
        $this->zoneTableid = $zoneTableid;
    }

And here is my error message:

Call to undefined function MLBP\BeerBundle\Controller\setZoneTableid() Thanks!

Was it helpful?

Solution

Be sure to use the -> operator instead of the . operator. Also, for this specific example you cannot set '20' as the zoneId as it is not the Entity representing a TableTable.

$game->setZoneTableid(<Some Table Entity>);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top