views:

456

answers:

2

Im using the symfony framework with mysql.

I have a field in mysql that is generated by doctrine as:

 weight:  { type: double, notnull: false, default: NULL }       


`weight`  double(18,2) NULL DEFAULT NULL

The value is entered using a textbox and the generated sql trys to insert '' into this field if no value is given.

This produces the following error:

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'weight' at row 1
  • How would change this value such that a Doctrine_Null gets used instead?
  • Also how would i be able to retrieve '(unknown)' for display purposes if the field is null?

Thanks

A: 

This should happen in your Form/Validation class. If you are expecting to have empty string values submitted then you need to convert those to null as part of this process.

As far as retrieving "unknown" for display i would probably do this as a custom getter on the model class.

prodigitalson
That would be the class MeasurementTable extends Doctrine_Table?Thanks
Dw
A: 

maybe you could try to use a validator on your form, like sfValidatorNumber ? http://www.symfony-project.org/api/1_4/sfValidatorNumber

FabienM
Ugh.. Perfect. I just assumed the generator of the model files would have picked a numeric validator. I will go back through everything and check all the generated files. Thanks
Dw