不能从返回的存储库查询调用实体函数


Can't call entity functions from a returned repository query

我正在尝试从symfony2和doctrine数据库中获取一个对象,使用我的实体类和存储库类之一。

下面是函数调用:

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

这是我的存储库类的一个片段:

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

这里是我的实体类的一个片段:

/**
 * 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;
    }

下面是我的错误信息:

调用未定义函数MLBP'BeerBundle'Controller'setZoneTableid()谢谢!

请确保使用->操作符而不是。操作符。另外,对于这个特定的例子,你不能将'20'设置为zoneId,因为它不是代表TableTable的实体。

$game->setZoneTableid(<Some Table Entity>);