问题
I'm using DoctrineExtensions and followed the docs. I have my Entity field decorated with the Sluggable annotation:
use Gedmo\Mapping\Annotation as Gedmo;
.
.
.
/**
* @Gedmo\Slug(fields={"city"}, updatable=false)
* @ORM\Column(length=255)
*/
private $slug;
When I try to persist a new entity I get an SQL error:
Persist:
$em = $this->getDoctrine()->getManager();
$em->persist($location);
$em->flush();
Error:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'slug' cannot be null
config.yml:
# Stof Doctrine Extensions
stof_doctrine_extensions:
orm:
default:
sluggable: true
According to the docs this is all I need, yet the slug is not being generated.
回答1:
This was something simple that I over looked. I did not have the field mapped in the orm.xml file... once I added this mapping it worked:
<field name="slug" type="string" column="slug" length="255" nullable="false">
<gedmo:slug fields="city" updatable="false" />
</field>
来源:https://stackoverflow.com/questions/22866698/slug-not-generated-when-persisting-entity-to-database