开发者

Doctrine 1.2 not creating tables from models in Zend Framework

开发者 https://www.devze.com 2023-03-29 21:10 出处:网络
I\'m trying to create tables from models by using: Doctrine::createTablesFromModels(APPLICATION_PATH . \'/models\');

I'm trying to create tables from models by using:

Doctrine::createTablesFromModels(APPLICATION_PATH . '/models');

Unlike generating the models from a Yaml file, which worked just fine, this does nothing at all. No errors, no warnings, nothing. The tables are not created. If I run the code below, it works just fine too:

Doctrine::dropDatabases();

So the database connection does work and the permissions are setup right. I've googled it in ten different ways without getting any helpful answers, so now I'm asking here.

Here is one of my base classes:

<?php

/**
 * BaseUser
 * 
 * This class has been auto-generated by the Doctrine ORM Framework
 * 
 * @property string $email
 * @property string $password
 * @property string $firstName
 * @property string $lastName
 * @property string $profileText
 * @property integer $role_id
 * @property Role $Role
 * @property Doctrine_Collection $UserDetail
 * @property Doctrine_Collection $CalendarItem
 * @property Doctrine_Collection $NewsItem
 * @property Doctrine_Collection $Link
 * @property Doctrine_Collection $TwitterUser
 * @property Doctrine_Collection $Tweet
 * 
 * @package    ##PACKAGE##
 * @subpackage ##SUBPACKAGE##
 * @author     ##NAME## <##EMAIL##>
 * @version    SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
 */
abstract class BaseUser extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('user');
        $this->hasColumn('email', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('password', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('firstName', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this->hasColumn('lastName', 'string', 255, array(
             'type' => 'string',
             'length' => '255',
             ));
        $this-开发者_开发技巧>hasColumn('profileText', 'string', null, array(
             'type' => 'string',
             'length' => '',
             ));
        $this->hasColumn('role_id', 'integer', 8, array(
             'type' => 'integer',
             'length' => 8,
             ));

        $this->option('collate', 'utf8_unicode_ci');
        $this->option('charset', 'utf8');
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne('Role', array(
             'local' => 'role_id',
             'foreign' => 'id'));

        $this->hasMany('UserDetail', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('CalendarItem', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('NewsItem', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('Link', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('TwitterUser', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $this->hasMany('Tweet', array(
             'local' => 'id',
             'foreign' => 'user_id'));

        $timestampable0 = new Doctrine_Template_Timestampable();
        $softdelete0 = new softDelete();
        $this->actAs($timestampable0);
        $this->actAs($softdelete0);
    }
}


The problem has been solved. I was using the softdelete functionality and I forgot to set:

$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);

This is necessary for softdelete to work. I also found out that in my generated models it used the wrong code for softdeletion:

$softdelete0 = new softDelete();

Instead of:

$softdelete0 = new Doctrine_Template_SoftDelete();


I had face this issue before that and after 3 days of searching i couldn't find a solution at the end of it i had moved to use symfony cli tool to generate sql and create db from yaml file

0

精彩评论

暂无评论...
验证码 换一张
取 消