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

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

问题描述

我有两个名为 Person 标签的模型。一个人有许多标签,标签主键是 person_id 标签 Person $ person $ tag in 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).

有一个数据字段( 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

但现在,我得到在类上没有名为contact的映射字段

But now, I get There is no mapped field named 'contact' on class Tag.

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天全站免登陆