My model
<?php
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('Identiti_Model_Akses', 'doctrine');
/**
* Identiti_Model_BaseAkses
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property string $nostaf
* @property integer $id_aplikasi
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME## <##EMAIL##>
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
abstract class Identiti_Model_BaseAkses extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('akses');
$this->hasColumn('nostaf', 'string', 12, array(
'type' => 'string',
'length' => 12,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('id_aplikasi', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
}
}
My actual table:
mysql> desc akses;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| nostaf | varchar(12) | NO | | NULL | |
| id_aplikasi | int(11) | NO | | NULL | |
+-------------+-------------+------+-----+---------+-------+
My code:
$q = Doctrine_Query::create()
->from('Identiti_Model_Akses a');
$result = $q->execute();
My error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a.id' in 'field list'. Failing Query: "SELECT a.id AS a__id, a.nostaf AS a__nostaf, a.id_aplikasi AS a__id_aplikasi FROM akses a"
I think it has something to do with the table itself (it doesn’t have any primary key). I’ve tried setting one of them as the primary key and the query doesn’t output the same error anymore.
Doctrine requires that a primary key is set. By default if you don’t have one set it will assume ‘id’ is the PK and attempt to select it. There is not a work around for this. You’re best off adding a PK with an auto increment.