Doctrine 1
  1. Doctrine 1
  2. DC-518

Generated *Table.class.php should contain a getInstance() method

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.2.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      Symfony 1.3 with Doctrine 1.2 on Debian 5.0 Linux

      Description

      I'm using the symfony framework but assume that the following only affects the classes that were auto generated by Doctrine.

      When doctrine generates the model classes for e.g. the sql table "manage_users" it generates:

       
        lib/model/doctrine/ManageUsers.class.php                           <- extends Doctrine_Table
        lib/model/doctrine/ManageUsersTable.class.php                 <- extends BaseManageUsers
        lib/model/doctrine/base/BaseManageUsers.class.php       <- extends sfDoctrineRecord
      

      As far as I understand the ManageUsersTable class is supposed to be autoloaded by Doctrine (cf. ATTR_AUTOLOAD_TABLE_CLASSES) and injected into
      the class returned by Doctrine::getTable('ManageUsers').

      The first problem is that it is hard to figure out for newbies how to access methods in this class because they try all means to instanciate it or looking for static methods but eventually fail

      The second problem is that using it this way, the IDE auto completion feature has no chance to figure out that the returned object offers methods defined in ManageUsersTable.class.php, it can only know that the results is an instance of Doctrine_Table.

      The third problem is that one has to repeatingly write Doctrine::getTable("ManageUser") in the source code which is quite error prone - or did you notice that I missed an "s" in the example just given The IDE has again no chance to spot this.

      A simple solution to all problems would be an auto generated getInstance method like this:

       
       class ManageUsersTable extends Doctrine_Table {
          /** Returns an instance of this class.
           *
           * @return ManageUsersTable
           */
          public static function getInstance() {
              return Doctrine::getTable('ManageUsers');
          }
       }
      

      This way one could write ManageUs<AUTOCOMPLETION>::getInstance()->get<AUTOCOMPLETION>(); and there would be far less typo bugs!

      bye,

      christian

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Christian Hammers
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: