学说 2 连接问题 [使用 xml 映射器]

发布于 2024-11-02 01:57:56 字数 1345 浏览 0 评论 0原文

我尝试连接两个表,但在编写正确的 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>

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

Doctrine\ORM\Mapping\MappingException - 房产街不存在

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2024-11-09 01:57:56

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

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

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

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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文