private function writeTable( $dir, $tableName, ezcDbSchemaTable $table )
    {
        $file = $this->openFile( $dir, $tableName );

        fwrite( $file, "\$def = new ezcPersistentObjectDefinition();\n" );
        fwrite( $file, "\$def->table = '$tableName';\n" );
        fwrite( $file, "\$def->class = '{$this->prefix}$tableName';\n" );

        $primaries = $this->determinePrimaries( $table->indexes );

        // fields 
        foreach ( $table->fields as $fieldName => $field )
        {
            $this->writeField( $file, $fieldName, $field, isset( $primaries[$fieldName] ) );
        }
        $this->closeFile( $file );
    }