Issues

ZF-180: Zend_Db_Table_Row: __get function maps incorrectly to _data

Description

I am unsure whether this is a problem with the pdo fetch function or if the problem is in the Zend_Db_Table_Row class. I'm guessing the first since I see that if you don't supply a data index in the config parameter to the constructor you use the array keys from $this->_info['cols'] as keys for the $this->_data member.

I changed the __get function to look for $camel in $this->_data instead of $under to get it to work, but it seems my array keys in $this->_data member is messed up: Shouldn't _data contain array('ID' => 35, 'FirmaID' => 0) ?

Zend_Db_Table_Row Object ( [_data:protected] => Array ( [id] => 35 [firmaid] => 0 ... ) [_info:protected] => Array ( [name] => cPerson [cols] => Array ( [ID] => id [FirmaID] => firmaid ... ) [primary] => ID ) )

Comments

Sorry, I should have done some checks with PDO first. I see you force lower-case in the Zend_Db_Adapter_Pdo_Abstract, so the problem is in the Zend_Db_Table_Row's __get function then ?

return $this->_data[$under];

should be:

return $this->_data[$camel];

Hi,

I belive i have expiranced the same problem today please allow me to explain:

I have noticed that the array $this->_info['cols'] on line 93 of Row.php returns a array of database field names mapped to lower case copies of these field names.

This array is then searched for the supplied field name in $camel and $under is assigned the true field names returned from the DB.

However all of $this_data's keys/fieldnames are lower case to same as $this->info['cols'], this results in a error as $under is set to the true field names not a lower case version.

Example:

$camel = "clientid"

$this->_info['cols'] = Array ("ClientID" = "clientid")

$under = "ClientID"

$this->_data = Array ("clientid" = "1")

so we get an error when:

return $this->_data[$under]; AKA ($this->_data['ClientID'])

I have temp patched this on my copy by placing $under = strltolower($under);

however i belive there is a far better way to fix this just not got the time at the mo.

Hope all that makes sence

Yup,

Seems you have same problem as I. Kinda hard to know what the right solution is as the docs doesn't say anything about upper-case field names only lower-case with underscores. Since it says you should use camelCase instead of underscores to access the row properties it made me thinking it would make a whole lot more sense to do $row->ClientID than $row->clientid. Thats what i initalially expected it to do when i started with zend_db_table, but it threw an exception at me.

I'm also experiencing this.

my table contains ID, Name, Username, Host

if I call $row->Name I get "exception 'Zend_Db_Table_Row_Exception' with message 'column 'Name' not in row'"

if I call $row->Name I get "Notice: Undefined index: Name in /home/freman/Documents/code/phprdiffbackup/trunk/htdocs/library/Zend/Db/Table/Row.php on line 96"

I also experienced this issue and resolved it by making the following modifications:

====================================== The Zend_Db_Inflector's camelize method, IMO should not run unless the name actually has underscores in it. If it does run, it automatically returns a lowercase version of the name which causes some mismatching of field names:

Index: library/Zend/Db/Inflector.php

  */
 public function camelize($name)
 {

+ if (strpos($name, '_') <= 0) { + return $name; + } // lowercase all, underscores to spaces, and prefix with underscore. // (the prefix is to keep the first letter from getting uppercased

// in the next statement.)

In addition, the describeTable method in Zend_Db_Adapter_Pdo_Mysql does not work properly if the ATTR_CASE attribute is set to anything except CASE_LOWER. This is because, by default, MySQL capitalizes the field names in the description and this must then be lowercased to create the description array.

Index: library/Zend/Db/Adapter/Pdo/Mysql.php

    $descr = array();
    foreach ($result as $key => $val) {

+ $val = array_change_key_case($val); $descr[$val['field']] = array( 'name' => $val['field'],

'type' => $val['type'],

I hope this helps . . . .

Changing fix version to 0.8.0.

Recategorize as Zend_Db_Table component.

As of revision 3995, the use of inflectors has been eliminated from Zend_Db_Table.