Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony2自定义存储库方法_Symfony_Doctrine Orm - Fatal编程技术网

Symfony2自定义存储库方法

Symfony2自定义存储库方法,symfony,doctrine-orm,Symfony,Doctrine Orm,我有一个实体League和Season,而Season与League有@manytone关系 现在,在我的联盟控制器的showAction中,我想为视图提供一个对象,该视图包含当前($id)联盟的所有赛季 因此,我在LeagueRepository中实现了一个FindallBelogingSeasons函数,如下所示: public function findAllBelongingSeasons($league_id) { return $this->getEntityManag

我有一个实体
League
Season
,而Season与League有
@manytone
关系

现在,在我的联盟控制器的
showAction
中,我想为视图提供一个对象,该视图包含当前($id)联盟的所有赛季

因此,我在
LeagueRepository
中实现了一个
FindallBelogingSeasons
函数,如下所示:

public function findAllBelongingSeasons($league_id)
{
    return $this->getEntityManager()
        ->createQuery('
            SELECT s FROM xxx:Season s
            WHERE s.league_id = :league_id'
        )
        ->setParameter('league_id', $league_id)
        ->getResult();
}
问题是,我现在得到的信息是,在赛季表的数据库中,本赛季没有舒尔的现场联赛id。但是doctrine现在希望通过对象在内部处理它,并且在季节中没有联盟id,因为它有一个属性
$league
,配置了
@ORM\manytone(targetEntity=“xxx\xxx\Entity\league”)

那么应该怎么做呢

感谢您的帮助:)

是正确的方式(在
league
中修改
league\u id

基本上,正如您所说,条令处理像“代理”一样用于访问db表和列的对象。这样,您必须引用doctirne(objects)映射和no-to-db对应字段

public function findAllBelongingSeasons($league_id)
{
    return $this->getEntityManager()
        ->createQuery('
            SELECT s FROM xxx:Season s
            WHERE s.league = :league_id'
        )
        ->setParameter('league_id', $league_id)
        ->getResult();
}