2011-11-05 36 views

回答

2

最後我找到了一種方法。我試圖做的是從控制器內部獲得專欄評論

//lets say we have a table named 'product' 
//and we want to get the comment from the 'name' column 
//first we get a list of columns from 'product' 
$columns = $this->getDoctrine()->getEntityManager()->getConnection()->getSchemaManager()->listTableColumns('product'); 
//then we just access getComment function from the 'Column' class 
//for the 'name' column: 
echo $columns['name']->getComment(); 
0

我懷疑這一點,Propel也是如此。兩者都使用PDO,而afaik沒有數據庫中立的方式來做到這一點。

爲了達到這個目的,你可以經常在系統表上使用SELECT語句來查詢表列(當然Oracle和PostgreSQL也允許這樣做)。但是,所涉及表格的名稱因供應商而異。 Here是如何獲取列名的,例如,在PostgreSQL中 - 獲取評論可能會非常相似。

ORM很可能會提供你想要的,但底層實現將是我上面概述的方法。也許你可以在Doctrine郵件列表中請求它?

+0

首先感謝您的努力。那麼,在內部,ORM心臟就是他們抽象的許多數據庫的「信息模式」,就像你上面在Oracle和PostgreSQL中所說的「系統表」一樣。例如,當ORM逆向工程創建映射(如Propel)時,他們從信息模式中獲取列名,外鍵,表名等,我知道你也可以從那裏獲得列註釋。問題是,學說怎麼做 – Thomas

+0

啊,好點。快速瀏覽DBAL源代碼可以在這裏找到[第284行](https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php) - 並且瞧,包括查看列註釋。大! – halfer