这个问题关系到我的另一个问题: Doctrine2给我相关的对象只有第一个实例
我想出了双向关联,试图解决我的老问题,但现在我还有一个问题。
模式[EDITED]:
XYZ\Bundle\CitiesBundle\Entity\Cities:
type: entity
table: cities
fields:
id:
id: true
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
name:
type: string
length: 50
fixed: false
nullable: false
landarea:
type: decimal
nullable: false
density:
type: integer
unsigned: false
nullable: false
population:
type: integer
unsigned: false
nullable: false
manyToOne:
state:
targetEntity: States
cascade: { }
inversedBy: cities
joinColumn:
state_id:
referencedColumnName: id
lifecycleCallbacks: { }
实体:
class Cities
{
//other vars
/**
* @var XYZ\Bundle\CitiesBundle\Entity\States
*/
private $state;
//other get/set
/**
* Set state
*
* @param XYZ\Bundle\CitiesBundle\Entity\States $state
*/
public function setState(\XYZ\Bundle\CitiesBundle\Entity\States $state)
{
$this->state = $state;
}
/**
* Get state
*
* @return XYZ\Bundle\CitiesBundle\Entity\States
*/
public function getState()
{
return $this->state;
}
}
class States
{
//other vars and get/set
private $cities;
public function __construct()
{
$this->cities = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Add cities
*
* @param XYZ\Bundle\CitiesBundle\Entity\Cities $cities
*/
public function addCities(\XYZ\Bundle\CitiesBundle\Entity\Cities $cities)
{
$this->cities[] = $cities;
}
/**
* Get cities
*
* @return Doctrine\Common\Collections\Collection
*/
public function getCities()
{
return $this->cities;
}
}
QueryBuilder的用法:
$query = $em->createQueryBuilder()
->select('c','s')
->from('CitiesBundle:Cities', 'c')
->innerJoin('c.state', 's')
->orderBy('c.population', 'DESC')
->setMaxResults(10)
->getQuery();
和一个错误是:
[语义错误] 0行,列58的ORDER BY c.population'邻近:错误:类XYZ \捆绑\ CitiesBundle \实体\城市没有协会命名状态
产生DQL:
选择C,S FROM CitiesBundle:城市℃的内部JOIN c.state的订单BY c.population DESC
耻辱:(
可能有人帮我解决我的问题?
[编辑]
我编辑的城市架构,现在的错误是:
注意:未定义指数:名称/home/marek/devel/sf2/cities/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php线473