2011-11-05 54 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