Search code examples
phpdatabasepostgresqlpomm

How does this class know what table to query?


http://pomm.coolkeums.org/documentation/manual-1.2#findwhere

It is possible to use it directly because we are in a Map class hence Pomm knows what table and fields to use in the query.

It says that because we are in Map class Pomm knows what table to query. How does it know what table I want to query?


Solution

  • from the link you provided

    "Map classes represent a structure in the database and provide methods to retrieve and save data with this structure. To be short, one table or view => one map class."

    This means that it knows which table YOU want to query because you are calling findWhere() from within the map class associated with that table.

    from the [Introspected tables] section of the link you provided here is a sample Map Class:

    *in the code below the object_name property specifies the table name related to this map class.*

     abstract class StudentMap extends BaseObjectMap
     {
         public function initialize()
         {
             $this->object_class =  '\College\PublicSchema\Student';
             $this->object_name  =  'student';
    
             $this->addField('reference', 'char');
             $this->addField('first_name', 'varchar');
             $this->addField('last_name', 'varchar');
             $this->addField('birthdate', 'timestamp');
             $this->addField('level', 'smallint');
             $this->addField('exam_dates', 'timestamp[]');
    
             $this->pk_fields = array('reference');
         }
     }