doctrine 2加入问题[与xml映射器]

时间:2011-04-18 12:05:03

标签: xml join annotations doctrine-orm mapper

我尝试连接两个表,但是写了正确的xml映射器(设置和实体访问测试并且工作正常)

  • 基于MySQL,Doctrine 2.0.4和ZF-1.11
  • 我正在使用XmlDriver('path \ to \ mappers);

查询

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

映射

<?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>

但是有了所有可能的关系(我在这里累了:)我总是遇到同样的问题:找不到相关实体的属性:

  

学说\ ORM \映射\ MappingException    - 物业街不存在

1 个答案:

答案 0 :(得分:0)

您已为街道字段提供了目标实体,但您必须提供一个映射回目标实体表,在本例中为“地址”。使用Doctrine 2 XML Mapping,这将是:

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

这假设地址表上的标识列名为“id”。