“无映射字段"在 Doctrine2 中使用部分查询和复合键时 [英] "No mapped field" when using partial query and composite keys in Doctrine2

查看:32
本文介绍了“无映射字段"在 Doctrine2 中使用部分查询和复合键时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个模型,分别称为 PersonTag.一个Person有多个Tag,Tag主键是person_idtag的复合键(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 中使用部分查询和复合键时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆