Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the options available for Doctrine's Doctrine_Core::generateModelsFromDb method?

Doctrine 1.2 has a method called generateModelFromDb, documented here, that generates model files for all of the tables in a database.

This function accepts an optional third parameter with an array of "options" to use when generating models, the specifics of which are not documented. What options are available for me to specify here?

like image 988
Tobias Cohen Avatar asked Apr 09 '10 05:04

Tobias Cohen


2 Answers

The complete list with default values from Doctrine/Import/Schema:

protected $_options = array('packagesPrefix'        =>  'Package',
                            'packagesPath'          =>  '',
                            'packagesFolderName'    =>  'packages',
                            'suffix'                =>  '.php',
                            'generateBaseClasses'   =>  true,
                            'generateTableClasses'  =>  false,
                            'generateAccessors'     =>  false,
                            'baseClassPrefix'       =>  'Base',
                            'baseClassesDirectory'  =>  'generated',
                            'baseClassName'         =>  'Doctrine_Record');
like image 55
BenV Avatar answered Oct 24 '22 05:10

BenV


Using Doctrine1.2.4 -

There are a few missing from that list - and they are important ones!

'pearStyle'             => true,
'classPrefix'           => '',
'classPrefixFiles'      => false,

I used this when generating my classes for a Zend Framework project, example script:

<?php

/**
 * Doctrine CLI script
 */

define('APPLICATION_ENV', 'development');

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    realpath(APPLICATION_PATH . '/../library/Doctrine'),
    get_include_path(),
)));

require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/config/default.ini'
);

$application->getBootstrap()->bootstrap('doctrine');

Doctrine::generateModelsFromDb(
    APPLICATION_PATH . '/modules/default/models/DbTable', 
    array('db1'),
    array(
        'pearStyle'            => true,
        'generateTableClasses' => true,
        'baseClassesDirectory' => '',
        'classPrefix'=> 'Model_DbTable_',
        'classPrefixFiles' => false,
        'baseClassPrefix' => 'Generated_'
     )
);
like image 37
Nick Avatar answered Oct 24 '22 06:10

Nick