0

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

 php app/console fos:elastica:populate

我得到这个错误:

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

似乎是什么问题,官员?

从 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 }
4

1 回答 1

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
        }
于 2014-01-24T21:49:03.010 回答