学说 2 连接问题 [使用 xml 映射器]
我尝试连接两个表,但在编写正确的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已为街道字段提供了目标实体,但您必须提供回目标实体表的映射,在本例中为“地址”。使用 Doctrine 2 XML 映射,这将是:
假设地址表上的标识列名为“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:
This assumes that the identity column on your addresses table is named 'id'.