Converting '' to NULL in doctrine and symfony
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(1开发者_如何学JAVA8,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
maybe you could try to use a validator on your form, like sfValidatorNumber ? http://www.symfony-project.org/api/1_4/sfValidatorNumber
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.
精彩评论