我收到以下错误消息:
Doctrine_Table_Exception:第237行的/home/public_html/projects/giftshoes/system/database/doctrine/Doctrine/Relation/Parser.php中的未知关系别名shoesTable
我正在使用带有Codeigniter的doctrine 1.2.2
我的代码如下:( BaseShoes.php和Shoes.php是自动生成的)
------------ ------------ BaseShoes
<?php
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('Shoes', 'sadiqsof_giftshoes');
/**
* BaseShoes
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property integer $sku
* @property string $name
* @property string $keywords
* @property string $description
* @property string $manufacturer
* @property float $sale_price
* @property float $price
* @property string $url
* @property string $image
* @property string $category
* @property Doctrine_Collection $Viewes
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*/
abstract class BaseShoes extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('shoes');
$this->hasColumn('sku', 'integer', 4, array(
'type' => 'integer',
'fixed' => 0,
'unsigned' => false,
'primary' => true,
'autoincrement' => false,
'length' => '4',
));
$this->hasColumn('name', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '255',
));
$this->hasColumn('keywords', 'string', 255, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '255',
));
$this->hasColumn('description', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('manufacturer', 'string', 20, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '20',
));
$this->hasColumn('sale_price', 'float', null, array(
'type' => 'float',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('price', 'float', null, array(
'type' => 'float',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('url', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('image', 'string', null, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '',
));
$this->hasColumn('category', 'string', 50, array(
'type' => 'string',
'fixed' => 0,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
'length' => '50',
));
}
public function setUp()
{
parent::setUp();
$this->hasMany('Viewes', array(
'local' => 'sku',
'foreign' => 'sku'));
}
}
-------------- ShoesTable --------
<?php
class ShoesTable extends Doctrine_Table
{
function getAllShoes($from = 0, $total = 15)
{
$q = Doctrine_Query::create()
->from('Shoes')
->limit($total)
->offset($from);
return $q->execute(array(), Doctrine::HYDRATE_ARRAY);
}
}
---------------鞋子型号-----------------
<?php
/**
* Shoes
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: Builder.php 6820 2009-11-30 17:27:49Z jwage $
*/
class Shoes extends BaseShoes
{
function __construct() {
parent::__construct();
$this->shoesTable = Doctrine::getTable('Shoes');
}
function getAllShoes()
{
return $this->shoesTable->getAllShoes();
}
}
答案 0 :(得分:6)
对于其他寻找答案的人,我遇到了这条错误消息,因为我有
Doctrine_Query::create()->from('Subscription s')->innerJoin('BillingPlan b')
而不是
Doctrine_Query::create()->from('Subscription s')->innerJoin('s.BillingPlan b')
关系需要与from()
中列出的模型相关答案 1 :(得分:1)
不确定为什么会出现此特定错误,但是,根据Doctrine的手册,您不应在__construct()
类(扩展Shoes
中定义BaseShoes
方法,它本身延伸Doctrine_Record
)
以下是Doctrine手册的部分内容:Overriding the Constructor (引用):
Doctrine不允许你覆盖
Doctrine_Record::__construct()
方法但提供了另一种选择
[...]
(我没有复制粘贴所有东西:那里有更多有趣的东西;-))
答案 2 :(得分:0)
删除构造函数而不对您删除的代码执行某些操作可能无济于事。
我是Doctrine的新手,但我最近遇到了同样的错误(我认为原因不同)。我想知道类属性$ this-&gt; shoesTable是否意味着外来关系,这将解释错误消息。在任何情况下,您可能不希望在行类中有一个表方法,所以我倾向于这样做:
Doctrine_Core::getTable('Shoes')->getAllShoes();
我知道你不太可能还在等待这个,但如果你想继续对话,请发布你的主叫代码。
答案 3 :(得分:0)
您尚未将$ shoesTable定义为Shoes对象上的属性。像这样添加:
class Shoes extends BaseShoes
{
private $shoesTable;
function __construct() {
parent::__construct();
$this->shoesTable = Doctrine::getTable('Shoes');
}
function getAllShoes()
{
return $this->shoesTable->getAllShoes();
}
}
如果不存在,则它不存在,并且引用它将调用Doctrine提供的__get()魔术方法。 Doctrine将假设shoesTable是数据模型的一部分,并寻找具有该名称的关系(因为它找不到任何本地数据)。
另一种更简单的方法是使用内置的getTable()方法:
class Shoes extends BaseShoes
{
function getAllShoes()
{
return $this->getTable()->getAllShoes();
}
}
答案 4 :(得分:0)
我遇到了相同的问题(在Symfony 1.4上),并且在完成所有检查(我已经开始Jobeet教程)之后,没有任何区别。
首先,您必须检查类和别名的名称(区分大小写)!如果一切都很好,请检查“关系”部分中的schema.yml,您必须添加外部列,还必须添加foreignAlias。我忘了
希望对您有帮助。
JobeetJob:
connection: doctrine
tableName: jobeet_job
...
relations:
JobeetCategory:
local: category_id
foreign: id
foreignAlias: JobeetJobs
type: one