Slug not generated when persisting Entity to Database

醉酒当歌 提交于 2019-12-25 03:08:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!