doctrine2与具有关联

时间:2016-04-08 14:01:49

标签: symfony doctrine-orm associations slug doctrine-extensions

我有ORM:

Something\SomeBundle\Entity\MyTable:
type: entity
table: my_table_name
id:
    id:
        type: bigint
        id: true
        generator:
            strategy: AUTO
fields:
    name:
        type: string
        length: '64'
        nullable: true
    slug:
        type: string
        length: '255'
        nullable: true
        gedmo:
            slug:
                separator: -
                style: default
                updatable: false
                fields:
                    - master
                    - name
manyToOne:
    master:
        targetEntity: Master
        joinColumn:
            name: master_id
            referencedColumnName: id

但是这对prod环境不起作用(错误:无法在实体中找到slug [master]作为映射属性 - Something \ SomeBundle \ Entity \ MyTable)。为什么?如何解决?

2 个答案:

答案 0 :(得分:1)

也许这会给你一些线索:

/**
 * @ORM\Column(type="string", length=200, nullable=false)
 * @Gedmo\Slug(
 *     fields={"name"},
 *     handlers={@Gedmo\SlugHandler(
 *             class="Gedmo\Sluggable\Handler\TreeSlugHandler",
 *             options={
 *                 @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
 *                 @Gedmo\SlugHandlerOption(name="separator", value="/")
 *             }
 *         )}
 * )
 */
private $slug;

答案 1 :(得分:1)

如果其他人有同样的问题我有解决方案

Something\SomeBundle\Entity\MyTable:
  type: entity
  table: my_table_name
  id:
    id:
      type: bigint
      id: true
      generator:
        strategy: AUTO
  fields:
    name:
      type: string
      length: '64'
      nullable: true
    slug:
      type: string
      length: '255'
      nullable: true
      gedmo:
        slug:
            handlers:
                'Gedmo\Sluggable\Handler\RelativeSlugHandler':
                    relationField: master
                    relationSlugField: id
                    separator: -
            separator: -
            style: default
            updatable: false
            fields:
                - name
  manyToOne:
    master:
      targetEntity: Master
      joinColumn:
        name: master_id
        referencedColumnName: id