Using MapBuilder Classes

When Propel generates the object model for you project, it also generates MapBuilder classes which are "static" classes that represent your database structure. These classes are used for determining, e.g., which columns ar primary keys, foreign keys, etc. at runtime without requiring any metadata operations on your database. As of Propel 1.3, these classes are only instantiated for your database model on-demand.

While you don't need to know anything about these classes -- since they are only used inside the generated base peer classes and core Propel classes -- they do provide an quick and powerful way to get metadata for your database.

Here is a brief example of how to use these classes. See the API Docs for more API information.

<?php

try {

  $dbMap = Propel::getDatabaseMap(BookPeer::DATABASE_NAME);

  $tables = $dbMap->getTables();

  foreach ($tables as $tableName => $table) {

    print "Table: $tableName\n";
    $columns = $table->getColumns();
    foreach ($columns as $column) {
      $creoleType = CreoleTypes::getCreoleName($column->getCreoleType());
      print "\tColumn: " . $column->getColumnName() . "\n";
      print "\t\tFQN: " . $column->getFullyQualifiedName() .  "\n";
      if ($column->isPrimaryKey()) {
        print "\t\tPrimary Key: true\n";
      }
      print "\t\tSize: " . $column->getSize() . "\n";
      print "\t\tType: " . $column->getType() . "\n";
    }
  }


} catch (Exception $e) {
  die("Exception: " . $e->__toString());
}