1
votes

I try to use the doctrine extension sortable via the gedmo extension. I installed the gedmo-package with composer and followed the instructions of the installation in symfony2. I use yaml-files as mapping-information for doctrine.

My yaml-file:

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]

The field position did have the type int, but I also tried string, because that should cause an error by the yaml-driver of the sortable-extension (InvalidMappingException).

But the error I always get is Integrity constraint violation: 19 NOT NULL constraint failed: pictures.position. But in all examples of the sortable extension there is no need to specifically set a value for the position-field or to allow null in the yaml-file. Also I suppose, that the InvalidMappingException should occur before the NOT NULL Exception.

Because of this I think that the extension is not even used. The config-files I use:

My config.yml file:

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

My doctrine_extensions.yml file:

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

1 Answers

0
votes

i know this question has been asked ages ago, but in case it can help: depending on versions you're using, you can try this syntax (this worked for me):

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

and if you need to sort by group, you need to add this into your relation (here is full example):

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