我知道这必须有一个简单的答案,但我无法弄清楚。眼泪后,我希望这里有人能提供帮助。

这是我的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
- 可以有多个配置文件

现在,在我的代码中,我可以在生成的身份和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

但是,当我在配置文件表上运行任何查询时,它将不起作用。甚至一个简单的查询,例如

        $q = Doctrine_Query::create()
          ->select('p.*')
          ->from('Profile p');
        echo $q->getSqlQuery();

失败。我尝试在“从“到promiles'”而不是“配置文件”中更改类名。依然没有。

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

有帮助吗?

解决方案

在更改了每个可能的变量并通过我的模型线路进行追踪之后,我遇到了一个令人尴尬的发现:

我正在调用学说查询的控制器称为profile.php。

profile.php

<?php
class Profile extends Controller {

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

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

}

当我将控制器命名以外的其他内容时,屁股很快就会突然起作用。例如,将其命名为compile.php:

温顺。php

<?php
class Docile extends Controller {

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

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

}

“配置文件”似乎不是Codeigniter中的保留单词(链接文字)。但是,似乎您无法从同名控制器类中调用学说为“表类”。

感谢您的输入。希望这能节省其他人类似的麻烦。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top