gegtot
Joined: 26 Nov 2007 Posts: 1
|
Posted: Mon Nov 26, 2007 11:35 pm Post subject: Constructor MDB_QueryTool_Result_Row ignores keys |
|
|
Hi all,
I use the class Bikes as a returnclass of BikesQT. In FetchBike($bikeno) I join the table, bike_types, and try to access its values using this returnclass.
My problem is that I cannot access the values of bike_types and I just found out why. When the query is built an initial '_' is added to every column name of the bike_types. When the contructor MDB_QueryTool_Result_Row returns the result, it skips every key beginning with '_'.
the query looks like this: SELECT bike_types.`id` AS `_bike_types_id`,bike_types.`type` AS `_bike_types_type`,bike_types.`pricetype` AS `_bike_types_pricetype`,bike_types.`bundle_size` AS `_bike_types_bundle_size`,bike_types.`time` AS `_bike_types_time`,bikes.`bike_id` AS `bike_id`,bikes.`lock_code` AS `lock_code`,bikes.`code_status` AS `code_status`,bikes.`status` AS `status`,bikes.`phone_number` AS `phone_number`,bikes.`type` AS `type`,bikes.`start_time` AS `start_time`,bikes.`end_time` AS `end_time`,bikes.`history_id` AS `history_id` FROM bikes,bike_types WHERE bikes.type = bike_types.type AND bikes.bike_id='test'
Is there a way of getting around this?
Best regards,
Georg
| Code: |
Class BikesQT extends MDB_QueryTool
{
public $table = 'bikes';
public $primaryCol = 'bike_id';
// protected $BikeFirstAttempt;
public $_bike_types_pricetype;
public $tableSpec = array(
array('name' => 'bikes', 'shortName' => 'bikes'),
array('name' => 'bike_types', 'shortName' => 'bike_types'),
);
function FetchBike($BikeNumber)
{
$this->addJoin('bike_types', 'bikes.type = bike_types.type');
$this->setSelect('bikes.bike_id', 'bike_types.price_type');
$BikeObj = $this->get($BikeNumber);
if ($BikeObj != null)
{
$SelectedBike = $BikeObj->fetchRow();
if($SelectedBike)
{
$SelectedBike->SetRented();
$SelectedBike->save();
}
return $SelectedBike;
}
else
{
return false;
}
}
}
Class Bikes extends MDB_QueryTool_Result_Row
{
public $bike_id;
public $status;
public $price_type;
public $bundle_size;
}
function MDB_QueryTool_Result_Row($arr, &$qt)
{
foreach ($arr as $key => $value) {
//Ignore keys beginning with '_'
if (substr($key,0,1) != '_') {
$this->$key = $value;
$this->_keyarray[] = $key;
}
}
$this->_qt_instance = $qt;
} |
|
|