其中映射类型来选择关联数组?学说ODM [英] Which mapping type to choose for associative Arrays? Doctrine ODM

查看:122
本文介绍了其中映射类型来选择关联数组?学说ODM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对一个简单的问题(顺便说一句实在太棒了!)学说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", ......);

在该类的$字段属性。

有关MongoDB的没问题,我知道,但在教义当我使用例如@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", ....)

有谁知道我应该为了在数据库中使用的原则,ODM的映射类型为preserve键 - 值对?

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)

推荐答案

应该是哈希类型:

<一个href=\"http://readthedocs.org/docs/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html?highlight=hash#hash\">http://readthedocs.org/docs/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html?highlight=hash#hash

这篇关于其中映射类型来选择关联数组?学说ODM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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