I know you said you "want to avoid adding logic to inspect the length of every field", but you didn't specify whether that was for performance reasons, or because there were many, and you didn't want to write the code individually. If it is the latter, I would use something like this on the Doctrine Record:
function set($fieldName, $value, $load = true) {
switch($fieldName) {
case 'id':
case 'foo':
case 'bar':
// list all of the fields that you DON'T want to truncate in this section
break;
default:
$value = substr($value, 0, 255);
}
parent::set($fieldName, $value, $load);
}
This function overrides the default set() method on the Record. It is going to truncate all fields to 255 characters that don't match the ones listed in the first part (id, foo, bar).
If that isn't what you want, you can let MySQL do the truncation, it issues a warning if you write past the column length (1265 | Data truncated for column 'xxx' at row 1
), but that is discarded by Doctrine as the query will complete. To do that, you can change the column type from "string" to "blob" and make the second parameter null instead of the column length, then just set the proper limits in MySQL.