Archive for July, 2008

Type confusions in Symfony

Thursday, July 24th, 2008

I post this merely to point out how easy it is to forget to check EVERYTHING when you appear to have a bug.

I’ve been trying unsuccessfully for the last hour to save a string to my database, like

$myString = 'test';
 
$object = new MyObject();
 
$object->setName($myString);
 
$object->save();

No matter how often I checked, including the requested value from the form submitting the data, the data held once in the object etc, the database only ever saved a 0.

So for example:

$myString = 'test';
 
$object = new MyObject();
 
$object->setName($myString);
 
$object->save();
 
echo $object->getName();

would give

test

Yet the value in the MySQl DB says 0, despite being set to a varchar(255).

So what was it? Propel. When I initially built the model, my schema.yml had defined ‘name’ as being an int. Of course, I had decided to change this, and changed it in the schema.yml… but forgot to rebuild the model… doh! The ORM was stepping in and saying “no, screw you buddy, you said this was an Int”

Written by baj | Posted on July 24th, 2008 in symfony |