Doctrine 1.2 – Unknown record property / related component in a DQL with only 1 table envolved-Collection of common programming errors
I’m trying to execute this DQL:
$q = Doctrine_Query::create()
->select('*');
->from('Clientes c');
$retorno = $q->execute();
My BaseClientes.php:
// Connection Component Binding
Doctrine_Manager::getInstance()->bindComponent('Clientes', 'padrao');
/**
* BaseClientes
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @property integer $pk_clientes
* @property string $txt_nome
* @property timestamp $ts_cadastro
* @property string $txt_diretorio
* @property Doctrine_Collection $Upload
*
* @package ##PACKAGE##
* @subpackage ##SUBPACKAGE##
* @author ##NAME##
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $
*/
abstract class BaseClientes extends Doctrine_Record
{
public function setTableDefinition()
{
$this->setTableName('clientes');
$this->hasColumn('pk_clientes', 'integer', 4, array(
'type' => 'integer',
'length' => 4,
'fixed' => false,
'unsigned' => false,
'primary' => true,
'autoincrement' => true,
));
$this->hasColumn('txt_nome', 'string', 255, array(
'type' => 'string',
'length' => 255,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('ts_cadastro', 'timestamp', null, array(
'type' => 'timestamp',
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
$this->hasColumn('txt_diretorio', 'string', 255, array(
'type' => 'string',
'length' => 255,
'fixed' => false,
'unsigned' => false,
'primary' => false,
'notnull' => true,
'autoincrement' => false,
));
}
public function setUp()
{
parent::setUp();
$this->hasMany('Upload', array(
'local' => 'pk_clientes',
'foreign' => 'fk_clientes'));
}
}
My table SQL:
CREATE TABLE `organizer`.`clientes` (
`pk_clientes` int(11) NOT NULL AUTO_INCREMENT,
`txt_nome` varchar(255) NOT NULL,
`ts_cadastro` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`txt_diretorio` varchar(255) NOT NULL,
PRIMARY KEY (`pk_clientes`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC
When I execute this DQL, it returns to me:
Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property / related component "clientes" on "Clientes"' in
/var/www/organizer/lib/php/doctrine/lib/Doctrine/Record/Filter/Standard.php:55 Stack trace: #0 /var/www/organizer/lib/php/doctrine/lib/Doctrine/Record.php(1382):
Doctrine_Record_Filter_Standard->filterGet(Object(Clientes), 'clientes') #1 /var/www/organizer/lib/php/doctrine/lib/Doctrine/Record.php(1337): Doctrine_Record->_get
('clientes', true) #2 /var/www/organizer/lib/php/doctrine/lib/Doctrine/Access.php(117): Doctrine_Record->get('clientes') #3 /var/www/organizer/lib/php/forger.php
(387): Doctrine_Access->offsetGet('clientes') #4 /var/www/organizer/app/clientes/model.php(20): forger->Table(Array) #5 /var/www/organizer/app/clientes/controller.php
(5): require_once('/var/www/organi...') #6 /var/www/organizer/web/index.php(9): require_once('/var/www/organi...') #7 {main} thrown in /var/www/organizer/lib/php/
doctrine/lib/Doctrine/Record/Filter/Standard.php on line 55
I really don’t know what is happening, I have this same situation in other file of my system and work.
Please, someone help me….
OBS: Sorry my bad english, I’m Brazilian.
-
Thanks for the answers, but I’ve found the “error”…
What I need is only recover the data in an array, so I searched in Google and found this:
$con = Doctrine_Manager::getInstance()->connection(); $res = $con->execute("SELECT * FROM clientes;", array(1)); $retorno = $res->fetchAll();
And this solved my problem because I was trying to use the return of $q->execute() as an array…
PS: Sorry for misspell xD…
Originally posted 2013-11-10 00:10:02.