I have a basic symfony2 form where I can set a value for my field.
I've just figured out that null values where saved as empty strings, where I expect an exception to be raised because thenull value is not accepted.
My mapping (within a trait) :
/**
* @ORM\Column(name="name", type="string", length=100, nullable=false)
*/
protected $name;
My field :
->add('name', null, array(
'label'=>'Nom détaillé',
'required' => false))
Setting required to true and defining assert rules works well but here I'm trying to solve this conversion issue.
If I put a vardumpin the SetName method, I do get a null value which is later saved as an empty string in my database. How can I solve that ?
EDIT : the show create table t
CREATE TABLE `recipe` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`isProduct` tinyint(1) NOT NULL,
`portions` int(11) DEFAULT NULL,
`nickname` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`shortDescription` varchar(500) COLLATE utf8_unicode_ci DEFAULT NULL,
`weight` decimal(10,2) DEFAULT NULL,
`isPrivate` tinyint(1) NOT NULL,
`name` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
`slug` varchar(128) COLLATE utf8_unicode_ci NOT NULL,
`content` longtext COLLATE utf8_unicode_ci,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
`viewCount` int(11) NOT NULL,
`parentId` int(10) unsigned DEFAULT NULL,
`userId` int(10) unsigned DEFAULT NULL,
`createdBy` int(10) unsigned DEFAULT NULL,
`updatedBy` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_DD24B40110EE4CEE` (`parentId`),
KEY `IDX_DD24B40164B64DCC` (`userId`),
KEY `IDX_DD24B401D3564642` (`createdBy`),
KEY `IDX_DD24B401E8DE7170` (`updatedBy`),
CONSTRAINT `FK_DD24B40110EE4CEE` FOREIGN KEY (`parentId`) REFERENCES `recipe` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_DD24B40164B64DCC` FOREIGN KEY (`userId`) REFERENCES `user` (`id`),
CONSTRAINT `FK_DD24B401D3564642` FOREIGN KEY (`createdBy`) REFERENCES `user` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_DD24B401E8DE7170` FOREIGN KEY (`updatedBy`) REFERENCES `user` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=101 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
show create table toutput?