Skip to content

PropelQuickBuilder: getDatabase() does not set the right platform #472

Closed
emagma opened this Issue Sep 21, 2012 · 2 comments

3 participants

@emagma
emagma commented Sep 21, 2012

Hi,
Trying to unit-test a behavior following this guide http://www.propelorm.org/cookbook/testing-your-behaviors.html I met and IDENTITY error at insert time in the sqlite database.
I changed the platform, adapter and dsn for using a mysql database and the issue remains.
I figured out that the getDatabase() method in PropelQuickBuilder does not pass the Platform to the Database object, and then the Dabase object uses the DefaultPlatform wihich returns "IDENTITY" for autoIncrement string.
I fixed my issue by modifying PropelQuickBuilder.php

// line 146
public function getSQL()
{
$this->getDatabase()->setPlatform($this->getPlatform());
return $this->getPlatform()->getAddTablesDDL($this->getDatabase());
}

Does anyone met this issue too ?

@oojacoboo

Hey, this is what I'm doing...

\Propel::setConnection("propel", \Propel::getConnection(SqliteSetup::$databaseName));

This makes my test db defined in the config my propel default and then all my models will work with the default connection. As for init the sqlite instance...

public static $databaseName = "test"; //where test is the name of the db in the config and schema
$this->con = \Propel::getConnection(self::$databaseName);

/**
 * Builds out the SQLite Database into memory based on the schema we pass into it
 * @param \PropelPDO $connection
 */
public function buildSqliteDb(\PropelPDO $connection = null) {
    if(!$connection)
        $connection = $this->con;

    $tables = $this->getTables();

    //if we don't have these tables in the array, build the tables
    if(!in_array("company", $tables) && !in_array("zip_code", $tables)) {
        $builder = new PropelQuickBuilderModified();

        $config = $builder->getConfig();
        $builder->setConfig($config);

        $schema = $this->getSchema();
        $builder->setSchema($schema);

        $builder->buildSQL($connection);
    }
}

Hope that helps get you somewhere.

@willdurand
Propel member
@willdurand willdurand closed this Nov 22, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.