Appendix C - 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.

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.

require_once("propel/Propel.php");

Propel::init("bookstore-conf.php");

require_once("Book.php");
require_once("Author.php");
require_once("Publisher.php");

require_once("propel/map/DatabaseMap.php");


try {

  $dbMap = Propel::getDatabaseMap("bookstore");

  $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";
      print "\t\tCreole Type: " . $creoleType . "\n";
    }
  }


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