3

I'm working with Doctrine2, and have a entity containing a string property that represents a WKT geometry:

class Entity {
    /** @Column(type="string") */
    protected $wkt;
}

I'd like to have this field transparently saved to a GEOMETRY field in the database, as such:

INSERT INTO ... VALUES(GeomFromText(?))
SELECT AsText(field) FROM ...

I had a look at the custom mapping types, but couldn't find where to apply such an SQL function.

Any idea?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
  • 1
    Just to clarify, you're hoping to update a field in the database whenever another field is modified? I'm not too familiar with Doctrine, but you could probably use [triggers](http://dev.mysql.com/doc/refman/5.1/en/triggers.html). – Michael Mior Oct 14 '11 at 11:38
  • No, actually I just need a transparent transformation between WKT (text) and Geometry (binary) when persisting/hydrating an entity! The database handles that with the GeomFromText() and AsText() SQL functions. – BenMorel Oct 14 '11 at 11:45

2 Answers2

0

Maybe you could look at LifecycleCallbacks:

/**
 * @PrePersist
 */
public function sendOptinMail() {
    //do sql query : SELECT GeoFromText()...
    $this->yourField = ...
}

and then set the field to the returned value.

  • That would mean injecting the db in my model, something I want to avoid... and does not give a solution for retrieving the value! – BenMorel Oct 14 '11 at 15:26
0

Just found out that this feature is not currently implemented, but a feature request does exist for it:

http://www.doctrine-project.org/jira/browse/DBAL-15

It might be available in Doctrine 2.2

Update: this feature has been confirmed for 2.2, which is to be release soon.

Update: this is now available in Doctrine 2.2!

BenMorel
  • 34,448
  • 50
  • 182
  • 322