我对 Doctrine 版本 1.1.0 中的列名的情况有疑问。
我有一个具有此定义的记录(实体):
abstract class BaseProductsXsell extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('products_xsell');
$this->hasColumn('ID', 'integer', 4, array('type' => 'integer', 'length' => 4, 'primary' => true, 'autoincrement' => true));
$this->hasColumn('products_id', 'integer', 4, array('type' => 'integer', 'length' => 4, 'unsigned' => 1, 'default' => '1', 'notnull' => true));
// and so on...
}
}
在 MySQL 数据库表中,“ID”的列名也是大写的。但是当我尝试在查询后获取列名时:
$query = Doctrine_Query::create()->select('m.*')->from("ProductsXsell m");
$collection = $query->execute();
$columns = $collection->getTable()->getColumnNames();
print_r($columns);
输出如下所示:
Array
(
[0] => id
[1] => products_id
...
)
我没有在任何地方设置学说连接的 case 属性,所以它应该是默认值(Doctrine::CASE_NATURAL)。
这会导致以下错误:
Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property / related component "id" on "ProductsXsell"' in /opt/hocatec/bin/libs/Doctrine/Doctrine/Record/Filter/Standard.php:55
Stack trace:
#0 /opt/hocatec/bin/libs/Doctrine/Doctrine/Record.php(1282): Doctrine_Record_Filter_Standard->filterGet(Object(ProductsXsell), 'id')
#1 /opt/hocatec/bin/libs/Doctrine/Doctrine/Record.php(1240): Doctrine_Record->_get('id', true)
#2 /opt/hocatec/bin/libs/Doctrine/Doctrine/Access.php(117): Doctrine_Record->get('id')
#3 /opt/hocatec/bin/models/HocaSync.php(368): Doctrine_Access->offsetGet('id')