问题描述
我有一个关于(顺便说一句真的很棒!)Doctrine ODM 的简单问题.
I have a simple question about the (by the way really great!) Doctrine ODM.
假设您有这样的文档:
/**
* @Document
*/
class Test
{
/** @Id */
public $id;
/** @WHICHTYPE */
public $field = array();
}
现在我想存储一个关联数组,例如
Now i want to store an associative array like
array("test" => "test1", "anothertest" => "test2", ......);
在该类的 $field 属性中.
In the $field property of that class.
我知道,MongoDB 没有问题,但是在 Doctrine 中,当我使用 @Collection 或简单地使用 @Field 时,只存储值(例如,在映射驱动程序中使用 array_values 进行收集).所以存储的值看起来像
No problem for MongoDB, I know, but in Doctrine when I use for example @Collection or simply @Field, only the values are stored (array_values is being used in the mapping driver for collection for example). So the stored value looks like
array("test1", "test2", ....)
有谁知道我应该使用哪种 Doctrine-ODM 映射类型来保存数据库中的键值对?
Does anyone know which Doctrine-ODM mapping type I should use in order to preserve the key-value pairs in the database?
提前谢谢你,
安迪(来自德国的问候)
Andi (greetz from germany)
推荐答案
应该是Hash类型:
这篇关于为关联数组选择哪种映射类型?原则 ODM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!