【问题标题】:Doctrine sortable extension in symfony3 - Error: Not Nullsymfony3 中的 Doctrine 可排序扩展 - 错误:非空
【发布时间】:2016-10-06 13:31:35
【问题描述】:

我尝试通过gedmo 扩展名使用教义扩展sortable。我用 composer 安装了 gedmo-package 并按照 the installation in symfony2 的说明进行操作。我使用yaml-files 作为学说的映射信息。

我的 yaml 文件:

AppBundle\Entity\Picture:
type: entity
table: pictures
id:
    id:
        type: integer
        generator: { strategy: AUTO }
fields:
   [...]
    type:
        type: string
        length: 20
    position:
        type: string
        gedmo:
            sortable:
                groups: [type]

字段位置确实有 int 类型,但我也尝试了 string,因为这会导致可排序扩展 (InvalidMappingException) 的 yaml 驱动程序出错。

但我总是得到的错误是Integrity constraint violation: 19 NOT NULL constraint failed: pictures.position。但在所有可排序扩展的 examples 中,无需专门为位置字段设置值或在 yaml 文件中允许为空。我还想,InvalidMappingException 应该出现在NOT NULL Exception 之前。

因此,我认为甚至没有使用扩展名。 我使用的配置文件:

我的 config.yml 文件:

imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: doctrine_extensions.yml}
[...]

我的学说_extensions.yml 文件:

services:
# KernelRequest listener
gedmo.listener.sortable:
    class: Gedmo\Sortable\SortableListener
    tags:
        - { name: doctrine.event_subscriber, connection: default }
    calls:
        - [ setAnnotationReader, [ "@annotation_reader" ] ]

【问题讨论】:

    标签: doctrine-orm symfony doctrine-extensions


    【解决方案1】:

    我知道这个问题很久以前就被问过了,但如果它可以提供帮助:根据您使用的版本,您可以尝试这种语法(这对我有用):

    #Resources/config/doctrine/Entity.orm.yml
    [...]  
    fields:  
      position:
          type: integer
          gedmo:
            - sortablePosition
    

    如果您需要按组排序,则需要将其添加到您的关系中(这里是完整示例):

      manyToOne:
        parent:
          targetEntity: Parent
          inversedBy: children
          joinColumn:
            name: parent_id
            referencedColumnName: id
            onDelete: cascade
          gedmo:
            - sortableGroup
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-30
      • 1970-01-01
      • 2012-06-01
      • 2012-03-09
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      相关资源
      最近更新 更多