2

I try to join two tables but get stuck writing correct xml mappers (setup and entity access tested and works fine)

  • Based on MySQL, Doctrine 2.0.4 and ZF-1.11
  • I am using the XmlDriver( 'path\to\mappers );

Query

$query = $em->createQueryBuilder()
    ->select('u')
    ->from('\Entities\Users', 'u')
    ->leftJoin('u.Addresses', 'a')
    ->getQuery();
$info = $query->getResult();

Mapper

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

  <entity name="Entities\Users" table="users">

    <change-tracking-policy>DEFERRED_IMPLICIT</change-tracking-policy>

    <id name="id" type="integer" column="id">
      <generator strategy="IDENTITY"/>
    </id>

    <field name="name" type="string" column="name"/>

    <many-to-one field="street" target-entity="Addresses" />

  </entity>
</doctrine-mapping>

But with all possible relations (I am getting tired here :) I always get the same problem: The property of the related entity is not found:

Doctrine\ORM\Mapping\MappingException - Property street does not exist

timt
  • 21
  • 1

1 Answers1

0

You have supplied a target entity for your street field, but You must provide a mapping back to the target entity table, in this case 'Addresses'. Using Doctrine 2 XML Mapping this would be:

<many-to-one field="street" target-entity="Addresses" inversed-by="id" />

This assumes that the identity column on your addresses table is named 'id'.

Richard
  • 422
  • 7
  • 17