This question is related to my other question: Doctrine2 gives me only the first instance of related objects
I came up with a bi-directional association to try to solve my old problem, but now I have a different problem.
Scheme [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: { }
Entities:
class Cities
{
private $state;
public function setState(\XYZ\Bundle\CitiesBundle\Entity\States $state)
{
$this->state = $state;
}
public function getState()
{
return $this->state;
}
}
class States
{
private $cities;
public function __construct()
{
$this->cities = new \Doctrine\Common\Collections\ArrayCollection();
}
public function addCities(\XYZ\Bundle\CitiesBundle\Entity\Cities $cities)
{
$this->cities[] = $cities;
}
public function getCities()
{
return $this->cities;
}
}
Using QueryBuilder:
$query = $em->createQueryBuilder()
->select('c','s')
->from('CitiesBundle:Cities', 'c')
->innerJoin('c.state', 's')
->orderBy('c.population', 'DESC')
->setMaxResults(10)
->getQuery();
and error:
[Semantic error] line 0, col 58 near ORDER BY c.population ': Error: class XYZ \ Bundle \ CitiesBundle \ Entity \ Cities does not have a named state association
generated DQL:
SELECT c, s FROM CitiesBundle: Cities with INNER JOIN c.state s ORDER BY c. Population DESC
shame: (
Can someone help me solve my problem?
[EDIT]
I edited the city map, now the error:
: Undefined index: name /home/marek/devel/sf 2/cities/vendor/doctrine/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php 473