Parent Child Relationship With A Single Entity In Doctrine 2

后端 未结 3 820
离开以前
离开以前 2021-01-12 16:50

I have database table that looks like this:

+----+--------+--------------------+
| id | parent | description        |
+----+--------+--------------------+
|  1 |          


        
3条回答
  •  一整个雨季
    2021-01-12 17:54

    To do this in YAML, the configuration would look something like:

    AppBundle\Entity\Category:
        type: entity
        table: category
        repositoryClass: AppBundle\Repository\CategoryRepository
        id:
            id:
                type: integer
                id: true
                generator:
                    strategy: AUTO
        oneToMany:
            children:
                targetEntity: Category
                mappedBy: parent
        manyToOne:
            parent:
                targetEntity: Category
                inversedBy: children
    

    Source: http://doctrine-orm.readthedocs.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-many-self-referencing

提交回复
热议问题