我試圖生成一個簡單的SQL選擇:簡單innerJoin主義查詢
SELECT c.com_id, c.pro_id, c.com_nombre
FROM bd_fn.fn_comuna c
inner join bd_fn.fn_provincia p
on (c.pro_id = p.pro_id)
where p.pro_nombre = 'namepro';
但DQL拋出這個錯誤:
Doctrine_Table_Exception' with message 'Unknown relation alias fn_provincia.
學說版本是1.XX,持續創造了通過視覺範式。 的DQL是這樣的:
$q = Doctrine_Query::create()
->select('c.com_id')
->from('fn_comuna c')
->innerJoin('c.fn_provincia p')
->where('p.pro_nombre=?',$namepro);
類fn_comuna.php
<?php
/**
* "Visual Paradigm: DO NOT MODIFY THIS FILE!"
*
* This is an automatic generated file. It will be regenerated every time
* you generate persistence class.
*
* Modifying its content may cause the program not work, or your work may lost.
*/
class Fn_comuna extends Doctrine_Record {
public function setTableDefinition() {
$this->setTableName('bd_fn.fn_comuna');
$this->hasColumn('com_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'unsigned' => false,
'notnull' => true,
'primary' => true,
'autoincrement' => false,
)
);
$this->hasColumn('pro_id', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'unsigned' => false,
'notnull' => true,
)
);
$this->hasColumn('com_nombre', 'string', 100, array(
'type' => 'string',
'length' => 100,
'fixed' => false,
'notnull' => true,
)
);
}
public function setUp() {
parent::setUp();
$this->hasOne('Fn_provincia as pro', array(
'local' => 'pro_id',
'foreign' => 'pro_id'
)
);
$this->hasMany('Fn_institucion as fn_institucion', array(
'local' => 'com_id',
'foreign' => 'com_id'
)
);
$this->hasMany('Fn_replegal as fn_replegal', array(
'local' => 'com_id',
'foreign' => 'com_id'
)
);
}
}
?>
你是什麼主義模式? – j0k
與數據庫相同嗎? bd_fn是sql模式。我用Visual Paradigm爲ORM創建了一個postgres數據庫,其中包含Doctrine 1.xx。加入是問題。我不知道爲什麼,如果這些表是相關的。 –
你的教義模型類「fn_comuna」裏面有什麼? – j0k