为什么ORM不会为我的1对多模型创建SQL查询?

为什么ORM不会为我的1对多模型创建SQL查询?,sql,orm,codeigniter,doctrine,doctrine-query,Sql,Orm,Codeigniter,Doctrine,Doctrine Query,我知道这个问题必须有一个简单的答案,但我想不出来。眼泪过后,我希望这里有人能帮忙 这是我的YML模型: Identity: columns: id: type: integer(10) primary: true autoincrement: true username: type: string(255) Profile: columns: id:

我知道这个问题必须有一个简单的答案,但我想不出来。眼泪过后,我希望这里有人能帮忙

这是我的YML模型:

Identity:
  columns:
    id:
      type:           integer(10)
      primary:        true
      autoincrement:  true
    username:
      type:           string(255)

Profile:
  columns:
    id:
      type:           integer(10)
      primary:        true
      autoincrement:  true
    identity_id:
      type:           integer(10)
    profiletype_id:
      type:           integer(10)
    name:
      type:           string(255)
  relations:
    Identity:
      local:          identity_id
      foreign:        id
      class:          Identity
      foreignAlias:   Profiles
    Profiletype:
      local:          profiletype_id
      foreign:        id
      class:          Profiletype
      foreignAlias:   Profiles

Profiletype:
  columns:
    id:
      type:           integer(10)
      primary:        true
      autoincrement:  true
    type:
      type:           string(255)
如您所见,生成了3个链接表:

身份
-可以有多个配置文件

个人资料
-只有一个身份
-有一个Profiletype

Profiletype
-可以有多个配置文件

现在,在我的代码中,我可以对生成的Identity和Profiletype模型执行查询

例如:

        $q = Doctrine_Query::create()
          ->select('i.*')
          ->from('Identity i');
        echo $q->getSqlQuery();
将工作并产生:

SELECT i.id AS i__id, i.username AS i__username FROM identity i
但是,当我在Profile表上运行任何查询时,它都不会工作。即使是一个简单的查询,如

        $q = Doctrine_Query::create()
          ->select('p.*')
          ->from('Profile p');
        echo $q->getSqlQuery();
失败了。我已尝试将FROM中的类名更改为“Profiles”,而不是“Profile”。还是没什么


任何关于我做错了什么的想法。

在更改了所有可能的变量并逐行跟踪我的模型后,我发现了一个令人尴尬的发现:

我从中调用条令查询的控制器名为profile.php

profile.php

<?php
class Profile extends Controller {

    function Profile()     {
        parent::Controller();
    }

    function index()     {
        $q = Doctrine_Query::create()
            ->from('Profile');
        echo $q->getSqlQuery();
    }

}
<?php
class Docile extends Controller {

    function Docile()     {
        parent::Controller();
    }

    function index()     {
        $q = Doctrine_Query::create()
            ->from('Profile');
        echo $q->getSqlQuery();
    }

}

嗯。。。无法重现您的错误。你犯了什么样的错误?我假设您正在使用mysql。您是否尝试过不太详细的模式定义,即:不为模型定义ID,只为关系定义foreignAlias。不重要,但值得一试。抛出的错误将是有用的。“基本”模型(或其他地方)中是否有可能被调用的自定义代码?@Darragh:是的,我使用的是mysql。我尝试过各种模式。在我的定义中,我通常不那么冗长,然而,考虑到我正在拼命工作,我试着在模式中完全拼写出来。还有其他想法吗?@drcolosos:“基本”模型中没有自定义代码。我在CodeIgniter框架的上下文中使用了原则。然而,我过去在CI/Doctrine中运行过一些模型——因此我认为是我的模型而不是CI造成了问题(特别是考虑到我可以调用关于标识和Profiletype的简单查询)。这就是wirded,我自己使用Doctrine和CodeIgniter,但从来没有遇到过问题。您是否检查了数据库中创建的表的设置是否正确?