“无映射字段"在 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
相关文章