quot;No mapped fieldquot; when using partial query and composite keys in Doctrine2(“无映射字段在 Doctrine2 中使用部分查询和复合键时)
问题描述
我有两个模型,分别称为 Person 和 Tag.一个Person有多个Tag,Tag主键是person_id和tag的复合键(Person $person and $tag 在 Doctrine2 中).
I have two models called Person and Tag. One Person has many Tags, and the Tag primary key is a composite key of person_id and tag (Person $person and $tag in Doctrine2).
Tag模型中有一个数据字段(BLOB),里面有很多数据.我正在设置一个不需要来自该字段的数据的查询,所以我想设置一个不检索该字段的查询.
There is a data field (BLOB) in the Tag model with a lot of data. I am setting up a query that does not require the data from that field, so I want to set up a query that does not retrieve that field.
我尝试了以下查询:
SELECT c, PARTIAL t.{tag} FROM Contact c LEFT JOIN c.tags
在这里,我得到了一些预期的错误类 Tag 的部分字段选择必须包含标识符.没问题,我添加联系人字段:
Here, I get the somewhat expected error The partial field selection of class Tag must contain the identifier. No problem, I add the contact field:
SELECT c, PARTIAL t.{contact,tag} FROM Contact c LEFT JOIN c.tags
但现在,我得到类标签上没有名为联系人"的映射字段.
Doctrine2 不支持对复合键的部分查询吗?
Does Doctrine2 not support partial queries on composite keys?
这是标签类:
/** @Entity @Table(name="tag") **/
class Tag
{
/** @Id @ManyToOne(targetEntity="Contact",inversedBy="tags") @var Contact **/
protected $contact;
/** @Id @Column(type="string",length=10,nullable=false) @var string **/
protected $tag;
/** @Column(type="blob") **/
protected $data;
}
推荐答案
每当执行部分选择时,您都需要包含您从中选择的类的主键.
Whenever performing a partial selection you need to include the primary key of the class you're selecting from.
您实际上并没有详细说明您的联系人"实体,但我假设该类的主键字段是id".如果是这种情况,那么以下查询将达到您的要求:
You haven't actually detailed your "Contact" entity but i'm assuming the primary key field of that class is "id". If this was the case then the following query will acheive what you're after:
SELECT c, PARTIAL t.{id, tag} FROM Contact c LEFT JOIN c.tags
这似乎没有记录:(
http://docs.doctrine-project.org/en/latest/reference/dql-doctrine-query-language.html#partial-object-syntax
这篇关于“无映射字段"在 Doctrine2 中使用部分查询和复合键时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“无映射字段"在 Doctrine2 中使用部分查询和复合键时
基础教程推荐
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
