From 228d8517c75d89a10fb12640e5f190a34aec9be0 Mon Sep 17 00:00:00 2001 From: Jan Sorgalla Date: Mon, 28 Nov 2011 21:06:01 +0100 Subject: [PATCH] Add type --- ...-conversion-using-custom-mapping-types.rst | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst b/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst index 5b79d2c4d..addf2751d 100644 --- a/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst +++ b/en/cookbook/advanced-field-value-conversion-using-custom-mapping-types.rst @@ -23,8 +23,8 @@ longitude/latitude pair to represent a geographic location. The entity ---------- -We create a simple entity which contains a field ``$point`` which should hold -a value object ``Point`` representing the latitude and longitude of the position. +We create a simple entity whith a field ``$point`` which holds a value object +``Point`` representing the latitude and longitude of the position. The entity class: @@ -32,7 +32,7 @@ The entity class: longitude; } } + +The mapping type +---------------- + +As you may have noticed, we used the custom type ``point`` in the ``@Column`` +docblock annotation of the ``$point`` field. + +Now we're going to create this type and implement all required methods. + +.. code-block:: php + + getLongitude(), $value->getLatitude()); + } + + return $value; + } + + public function convertToPHPValueSQL($sqlExpr, AbstractPlatform $platform) + { + return sprintf('AsText(%s)', $sqlExpr); + } + + public function convertToDatabaseValue($sqlExpr, AbstractPlatform $platform) + { + return sprintf('GeomFromText(%s)', $sqlExpr); + } + } + +A few notes about the implementation: + + * \ No newline at end of file