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();
}