Error: Class ... \ Entity \ .. does not have an association with the name

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

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

+3
2

, joinColumns: ( ) Many-To-Many. joinColumn.

Cities XML :

joinColumn:
    name: state_id
    referencedColumnName: id

, "ManyToOne" "manyToOne" XML, , ...

, ...

+2

, Symfony YAML . , YAML.

+2

All Articles