0

I have an embedded document in my Doctrine ODM Document when I run this command

 php app/console fos:elastica:populate

I get this Error :

Object of class ng\myBundle\Document\Coordinates could not be converted to string in /usr/share/nginx/www/project/vendor/friendsofsymfony/elastica-bundle/FOS/ElasticaBundle/Transformer/ModelToElasticaAutoTransformer.php on line 139

what seems to be the problem, officers ?

Code from 137 to 141 :

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

my mapping:

 mappings:
                        title: { boost: 5 }
                        coordinates: {type:geo_point,lat_lon:true, boost: 5 }
Aysennoussi
  • 3,720
  • 3
  • 36
  • 60

1 Answers1

0

Try to use this code without string converting:

        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
        }
Victor Bocharsky
  • 11,930
  • 13
  • 58
  • 91
  • But then it wouldn't guess the type of field, It's no matter for me because all fields are typed I'll try that and see what happens – Aysennoussi Jan 24 '14 at 21:50
  • It will work but will the search work ? That's what I'm going to verify now :) – Aysennoussi Jan 24 '14 at 22:00
  • With `var_dump` you must to dump `$v` var and find any public method that you need to call for convert `$v` object to `string` or to `scalar` value. And then replace var_dump by calling this method like: `$v = (string)$v->callAnyToStringOrToScalarMethod()`; – Victor Bocharsky Jan 24 '14 at 22:05
  • but wouldn't this affect my search, I think I just need to declare geo_point in mapping .. but it seems it's more complicated Any way , I'm through testing now , and I'll e back with results – Aysennoussi Jan 24 '14 at 22:08