Mysql中的关系问题,教义得到此错误:Doctrine_Table_Exception:未知的关系别名Model_Training

问题描述

| 我对教义中的关系有疑问。适用于MysqL数据库。使用关系下载数据时会发生此问题,引发此错误:Doctrine_Table_Exception:未知关系别名Model_Training 请帮助我厌倦它,有几天我坐在上面,却什么也没有发生,谷歌也没有找到任何东西。 这是检索数据的代码
$daTarows = Doctrine_Query::create()
                    ->from(\'Model_Training a\')->where(\'a.idTrainings = ?\',$this->_getParam(\'id\'))
                    ->leftJoin(\'a.Model_TrainingBonuse ac\')
                    ->leftJoin(\'a.Model_Bonuse ad\')
                    ->fetchArray();
具有Schema.yml文件的教义模型的形成:
TrainingBonuse:
  tableName: Trainings_has_Bonuses
  columns:
    Trainings_idTrainings:
      type: integer(4)
      notnull: true
      autoincrement: true
    Bonuses_idBonuses:
      type: integer(4)
      notnull: true
  relations:
    TrainingsIdTraining:
      class: Training
      local: Trainings_idTrainings
      foreign: idTrainings
      foreignAlias: Trainings_has_Bonuses
    BonusesIdBonuse:
      class: Bonuse
      local: Bonuses_idBonuses
      foreign: idBonuses
      foreignAlias: Trainings_has_Bonuses
  indexes:
    fk_Trainings_has_Bonuses_Bonuses1:
      fields: [Bonuses_idBonuses]
    fk_Trainings_has_Bonuses_Trainings1:
      fields: [Trainings_idTrainings]
  options:
    charset: utf8
    collate: utf8_polish_ci

Bonuse:
  tableName: Bonuses
  columns:
    idBonuses:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    name:
      type: string(45)
    title:
      type: string(255)
    description:
      type: clob(65535)
    file_url_full:
      type: string(255)
    file_type:
      type: integer(1)
    width_full:
      type: integer(4)
    height_full:
      type: integer(4)
    active:
      type: integer(1)
      default: 1
  options:
    charset: utf8
    collate: utf8_polish_ci

Training:
  tableName: Trainings
  columns:
    idTrainings:
      type: integer(4)
      primary: true
      notnull: true
      autoincrement: true
    title:
      type: string(255)
    sub_title:
      type: string(255)
    up_body:
      type: clob(65535)
    training_body:
      type: clob(65535)
    question:
      type: clob(65535)
    opinion:
      type: clob(65535)
    bonuses:
      type: integer(1)
      notnull: true
      default: 0
    down_body:
      type: clob(65535)
    modyfication:
      type: integer(1)
      notnull: true
      default: 0
    active:
      type: integer(1)
      notnull: true
      default: 1
  options:
    charset: utf8
    collate: utf8_polish_ci
楷模: 训练
abstract class Model_Base_Training extends Doctrine_Record
{
    public function setTableDeFinition()
    {
        $this->setTableName(\'Trainings\');
        $this->hasColumn(\'idTrainings\',\'integer\',4,array(
             \'type\' => \'integer\',\'primary\' => true,\'autoincrement\' => true,\'length\' => \'4\',));
        $this->hasColumn(\'title\',\'string\',255,array(
             \'type\' => \'string\',\'length\' => \'255\',));
        $this->hasColumn(\'sub_title\',));
        $this->hasColumn(\'up_body\',\'clob\',65535,array(
             \'type\' => \'clob\',\'length\' => \'65535\',));
        $this->hasColumn(\'training_body\',));
        $this->hasColumn(\'question\',));
        $this->hasColumn(\'opinion\',));
        $this->hasColumn(\'bonuses\',1,\'notnull\' => true,\'default\' => 0,\'length\' => \'1\',));
        $this->hasColumn(\'down_body\',));
        $this->hasColumn(\'modyfication\',));
        $this->hasColumn(\'active\',\'default\' => 1,));

        $this->option(\'collate\',\'utf8_polish_ci\');
        $this->option(\'charset\',\'utf8\');
        $this->option(\'type\',\'InnoDB\');
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasMany(\'Model_UserTraining as Users_has_Trainings\',array(
             \'local\' => \'idTrainings\',\'foreign\' => \'Trainings_idTrainings\'));

        $this->hasMany(\'Model_TrainingBonuse as Trainings_has_Bonuses\',\'foreign\' => \'Trainings_idTrainings\'));
    }
}
TRAINING_BONUSES
abstract class Model_Base_TrainingBonuse extends Doctrine_Record
{
    public function setTableDeFinition()
    {
        $this->setTableName(\'Trainings_has_Bonuses\');
        $this->hasColumn(\'Trainings_idTrainings\',));
        $this->hasColumn(\'Bonuses_idBonuses\',));


        $this->index(\'fk_Trainings_has_Bonuses_Bonuses1\',array(
             \'fields\' => 
             array(
              0 => \'Bonuses_idBonuses\',),));
        $this->index(\'fk_Trainings_has_Bonuses_Trainings1\',array(
             \'fields\' => 
             array(
              0 => \'Trainings_idTrainings\',));
        $this->option(\'collate\',\'InnoDB\');
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasOne(\'Model_Training as TrainingsIdTraining\',array(
             \'local\' => \'Trainings_idTrainings\',\'foreign\' => \'idTrainings\'));

        $this->hasOne(\'Model_Bonuse as BonusesIdBonuse\',array(
             \'local\' => \'Bonuses_idBonuses\',\'foreign\' => \'idBonuses\'));
    }
}
奖金
abstract class Model_Base_Bonuse extends Doctrine_Record
{
    public function setTableDeFinition()
    {
        $this->setTableName(\'Bonuses\');
        $this->hasColumn(\'idBonuses\',));
        $this->hasColumn(\'name\',45,\'length\' => \'45\',));
        $this->hasColumn(\'description\',));
        $this->hasColumn(\'file_url_full\',));
        $this->hasColumn(\'file_type\',));
        $this->hasColumn(\'width_full\',));
        $this->hasColumn(\'height_full\',\'InnoDB\');
    }

    public function setUp()
    {
        parent::setUp();
        $this->hasMany(\'Model_TrainingBonuse as Trainings_has_Bonuses\',array(
             \'local\' => \'idBonuses\',\'foreign\' => \'Bonuses_idBonuses\'));
    }
}
    

解决方法

        您的schema.yml文件中没有\\“ Model_Training \\\”表定义…尽管\\\\\\“培训\\\\\\\\\\\”别名类\或\\\“外部别名\”您在schema.yml中指定的元素,则使用表定义的名称。因此,请使用\“ Training \”(而不是\“ Model_Training \”)(这也适用于\“ Model_Bonuses \”以及其他)。