Search code examples
symfonydoctrine-ormmysql-spatial

Symfony2/Doctrine2-spatial : Class 'Contains' is not defined


i am using https://github.com/djlambert/doctrine2-spatial and i have an error when trying a query with the "contains" function

firstly, if i put this :

dql:
    numeric_functions:
       Contains:     CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains

under orm like in doc (https://github.com/djlambert/doctrine2-spatial/blob/master/INSTALL.md), i have this error :

[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
Unrecognized options "dql" under "doctrine.orm"

but if i put it under doctrine.orm.entity_managers.default there is no error but i still have an error when running the query, here is my code :

$sql = 'SELECT DemoTadBundle:DeliveryZone dz WHERE Contains(dz.area, :point)'; //dz.area is of type polygon
$converter = new SpatialConverter();
$q = $this->_em->createQuery($sql)->setParameter('point', $converter->convertToDatabaseValue($address->getPoint())); //$address->getPoint returns an CrEOF\Spatial\PHP\Types\Geometry\Point object
return $q->getOneOrNullResult();

and here is the error :

[Semantical Error] line 0, col 41 near 'Contains(dz.area,': Error: Class 'Contains' is not defined.

can someone help me to resolve this problem ?

my symfony version is 2.5

thank you.


Solution

  • i resolved my problem, it seems that i was mixing the short and the complete syntax, here is my entire config.yml file (only the doctrine section)

    i hope this will help :)

    doctrine:
        dbal:
            driver:   "%database_driver%"
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
            charset:  UTF8
            types:
                geometry:   CrEOF\Spatial\DBAL\Types\GeometryType
                point:      CrEOF\Spatial\DBAL\Types\Geometry\PointType
                polygon:    CrEOF\Spatial\DBAL\Types\Geometry\PolygonType
                linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType
        orm:
            auto_generate_proxy_classes: "%kernel.debug%"
            entity_managers:
                default:
                    dql:
                        numeric_functions:
                            Contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
                            AsText: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsText
                            AsBinary: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\AsBinary
                            GeomFromText: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
    
                    auto_mapping: true
                    mappings:
                        gedmo_tree:
                            type:       annotation
                            prefix:     Gedmo\Tree\Entity
                            dir:        "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
                            alias:      GedmoTree # this one is optional and will default to the name set for the mapping
                            is_bundle:  false