Hi!
Found this strange behavior when I was tracking down a bug on my Cake
application.
The easiest way is to reproduce this is to create the following sample
application.
1. Set up the database:
2. Create the following table to the database
CREATE TABLE `cars` (
`id` int(11) NOT NULL auto_increment,
`type` varchar(16) collate latin1_general_ci NOT NULL,
`name` varchar(50) collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
COLLATE=latin1_general_ci;
INSERT INTO `cars` VALUES (1,'00:54:22:77','Audi'),
(2,'00:44:jk:bb','Volvo'),(3,'12:56','Jaguar'),(4,'12','Ford');
3. Download and setup the latest stable version of cake (1.1.19.6305)
(make sure that you change the debug value to 2 in core.php)
4. Create the controller file (cars_controller.php)
<?php
class CarsController extends AppController
{
function index()
{
$something = array("a" => "asdf", "b" => "12");
$this->set('car', $this->Car->find(array("type" =>
$something['b'])));
}
}
?>
5. Create the model (car.php):
<?php
class Car extends AppModel
{
var $name = "Car";
}
?>
6. create a view (index.thtml):
<?php debug($car); ?>
7. Run the script (for example: localhost/cake/cars)
Cake executes the following SQL statement:
SELECT `Car`.`id`, `Car`.`type`, `Car`.`name` FROM `cars` AS `Car`
WHERE `type` = 12 LIMIT 1;
and returns the wrong field. It return the Jaguar when it should
return the Ford
The correct statement would be:
SELECT `Car`.`id`, `Car`.`type`, `Car`.`name` FROM `cars` AS `Car`
WHERE `type` = '12' LIMIT 1;
Is there a workaround for this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---