Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1503

Add support for executing custom SQL functions on custom types

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      I have created a custom type called point but need a way to have a function called on columns of this type when fetching / updating / inserting entities.

      For example:

      Consider I have an entity which has a column called the_geom

      This is associated with my custom type point

      A basic select statement for this entity is as follows:

      SELECT id, name, the_geom FROM points where id = 1

      The problem is the_geom is encoded and on the PHP side I want it in human readable form. I would like a way to specify custom functions on SELECT / INSERT / UPDATE for columns of this custom type.

      When selecting my entity I would like to execute the function ST_AsText(the_geom)

      SELECT id, ST_AsText(the_geom) FROM points where id = 1

      The same goes for updates and inserts. I would like to surround the column SQL with other custom functions, to encode my human readable text back to the encoded value for the DB.

      Possibly this could be integrated into Doctrine\DBAL\Types\Type ?

      // Modify the column SQL for insert
      public function getSqlInsertColumn(....)
      
      // Modify the column SQL for update
      public function getSqlUpdateColumn(....)
      
      // Modify the column SQL for select
      public function getSqlSelectColumn(....)
      
      // A possible example of getSqlSelectColumn(...)
      public function getSqlSelectColumn($doctrineSql)
      {
          // $doctrineSql == "p0_.the_geom"
          return 'ST_AsText(' . $doctrineSql . ')';
      }
      
      1. 022-doctrine-basic-entity-persister.diff
        5 kB
        Lars Strojny
      2. 024-doctrine-many-to-many-persister.diff
        3 kB
        Lars Strojny
      3. 025-doctrine-unit-of-work.diff
        2 kB
        Lars Strojny
      4. 029-doctrine-query.diff
        1 kB
        Lars Strojny
      5. doctrine-type.diff
        0.4 kB
        Benjamin Morel

        Issue Links

          Activity

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Dylan Arnold
            • Votes:
              6 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: