无法在Elastica中填充doctrine嵌入式文档

时间:2014-01-24 20:13:23

标签: symfony doctrine-orm elastica

运行此命令时,我的Doctrine ODM文档中有一个嵌入式文档

 php app/console fos:elastica:populate

我收到此错误:

  

类ng \ myBundle \ Document \ Coordinates的对象无法在/usr/share/nginx/www/project/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/Transformer/ModelToElasticaAutoTransformer.php上转换为字符串139

人员似乎是什么问题?

代码从137到141:

if ($v instanceof \DateTime) {
                $v = $v->format('c');
            } elseif (!is_scalar($v) && !is_null($v)) {
                $v = (string)$v;
            }

我的映射:

 mappings:
                        title: { boost: 5 }
                        coordinates: {type:geo_point,lat_lon:true, boost: 5 }

1 个答案:

答案 0 :(得分:0)

尝试在没有string转换的情况下使用此代码:

        if ($v instanceof \DateTime) {
            $v = $v->format('c');
        } elseif (!is_scalar($v) && !is_null($v)) {
            //$v = (string)$v // if you want that it work, add `__toString()` magic method in `$v` object class
            var_dump($v); // or try to dump var and find to method that you need to call
        }