【问题标题】:Slug not generated when persisting Entity to Database将实体持久保存到数据库时未生成 Slug
【发布时间】:2014-05-16 23:56:08
【问题描述】:

我正在使用 DoctrineExtensions 并遵循文档。我的 Entity 字段装饰有 Sluggable 注释:

   use Gedmo\Mapping\Annotation as Gedmo;
   .
   .
   .
   /**
     * @Gedmo\Slug(fields={"city"}, updatable=false)
     * @ORM\Column(length=255)
     */
    private $slug;

当我尝试持久化一个新实体时,我收到一条 SQL 错误:

坚持:

        $em = $this->getDoctrine()->getManager();
        $em->persist($location);
        $em->flush();

错误:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'slug' cannot be null

config.yml:

# Stof Doctrine Extensions
stof_doctrine_extensions:
    orm:
        default:
            sluggable: true

根据docs,这就是我所需要的,但没有生成slug。

【问题讨论】:

    标签: symfony slug doctrine-extensions


    【解决方案1】:

    这很简单,我看过了。我没有在 orm.xml 文件中映射该字段...一旦添加此映射,它就起作用了:

    <field name="slug" type="string" column="slug" length="255" nullable="false">
        <gedmo:slug fields="city" updatable="false" />
    </field>
    

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 2020-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      相关资源
      最近更新 更多