具有多种类型的Doctrine mongoDB ODM字段

具有多种类型的Doctrine mongoDB ODM字段,doctrine,doctrine-odm,Doctrine,Doctrine Odm,我需要在一个字段中存储整数和字符串值。我应该在映射中使用什么类型?当我使用字符串时,我会在我的mongo文档中获取整数值作为字符串。使用字符串映射。如果需要返回不同的类型,则在字段的getter中。用这样的东西 public function getTransgenderField() { if (is_numeric($this->transgenderField)) { return (int) $this->transgenderField; }

我需要在一个字段中存储整数和字符串值。我应该在映射中使用什么类型?当我使用字符串时,我会在我的mongo文档中获取整数值作为字符串。

使用字符串映射。如果需要返回不同的类型,则在字段的getter中。用这样的东西

public function getTransgenderField() {
    if (is_numeric($this->transgenderField)) {
        return (int) $this->transgenderField;
    }
    return $this->transgenderField;
}
只需使用
@ODM/Field(type=“raw”)
注释:


你能提供一个有数据的例子吗?如果您想在MongoDB中使用混合类型,就不能使用doctrine,因为据我所知,字段中没有混合类型。
/**
 * @ODM/Field(type="raw")
 */
protected $value;