StofDoctrineExtensionsBundle icon indicating copy to clipboard operation
StofDoctrineExtensionsBundle copied to clipboard

[tree] Unable to find ancestor/parent child relation through ancestor field

Open titomiguelcosta opened this issue 13 years ago • 1 comments

I'm trying to use the Tree Doctrine Extension in my Symfony 2.1 project, but i get the following error when creating the schema (php app/console doctrine:schema:update --force):

[Gedmo\Exception\InvalidMappingException]
Unable to find ancestor/parent child relation through ancestor field - [parent] in class - Zorbus\ArticleBundle\Entity\Category

I have enabled the extension in app/config/config.yml:

stof_doctrine_extensions:
    default_locale: %locale%
    orm:
        default:
            timestampable: true
            sluggable: true
            tree: true

Here is my Entity:

Zorbus\ArticleBundle\Entity\Category:
    type: entity
    table: zorbus_article_category
    repositoryClass: Zorbus\ArticleBundle\Entity\CategoryRepository
    gedmo:
        tree:
            type: nested
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 255
            nullable: false
        description:
            type: text
            nullable: true
        lang:
            type: string
            length: 5
            nullable: true
            default: en
        image:
            type: string
            length: 255
            nullable: true
        is_highlighted:
            type: boolean
            default: false
            nullable: true
        is_enabled:
            type: boolean
            default: true
            nullable: true
        lft:
            type: integer
            gedmo:
                - treeLeft
        rgt:
            type: integer
            gedmo:
                - treeRight
        root:
            type: integer
            nullable: true
            gedmo:
                - treeRoot
        lvl:
            type: integer
            gedmo:
                - treeLevel
        user_id:
            type: integer
            nullable: true
        slug:
            type: string
            length: 255
            nullable: true
            gedmo:
                slug:
                    separator: '-'
                    style: default
                    fields:
                        - name
        created_at:
            type: datetime
            nullable: true
            gedmo:
                timestampable:
                    on: create
        updated_at:
            type: datetime
            nullable: true
            gedmo:
                timestampable:
                    on: update
    manyToOne:
        parent:
            targetEntity: Category
            inversedBy: children
            joinColumn:
                name: parent_id
                referencedColumnName: id
                onDelete: SET NULL
            gedmo:
                - treeParent
    oneToMany:
        children:
            targetEntity: Category
            mappedBy: parent
            orderBy:
                lft: ASC
    manyToMany:
        articles:
            targetEntity: Article
            mappedBy: categories

Entities and Repository classes are generated successfully (php app/console generate:doctrine:entities Zorbus). What is wrong?

In my composer. json:

"stof/doctrine-extensions-bundle": "dev-master",

and in my AppKernel.php:

new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),

thanks

titomiguelcosta avatar Oct 17 '12 00:10 titomiguelcosta

Hi, I could fixed this issue with change (use your own bundle and namespace):

targetEntity: Category

to

targetEntity: MyNamespace\MySuperBundle\Entity\Category

renta avatar Jan 08 '13 13:01 renta