How to manage the entity more convenient in the sonata backend #5146

Closed
opened 2026-01-22 14:59:37 +01:00 by admin · 3 comments
Owner

Originally created by @ghost on GitHub (Jun 8, 2016).

Originally assigned to: @guilhermeblanco on GitHub.

Hi,

I'm learning symfony2 about sonata-admin-bundle; There are three tables goodscategory and brand, I want to show or edit category.name and brand.name in the backend page(goods listView),it will be very convenient for administrator to manage them;

error_01

error_02

It shows category.name is built with "many-to-one" relation successfuly, and the second relation between

brand and goods is not work

I have two questions:

1、Is the "yml" file just can contain one "many-to-one" relationship?

2、If Iwant to manage the goods info in one page,(please refer the picture),what should I do?

Here is some code below:

brand.orm.yml

Application\Sonata\MallBundle\Entity\Brand:
    type: entity
    table: brand
    ...
    oneToMany:
        goods:
            targetEntity: Goods
            mappedBy: brand
    lifecycleCallbacks: {  }

goods.orm.yml

Application\Sonata\MallBundle\Entity\Goods:
    type: entity
    table: goods
    repositoryClass: Application\Sonata\MallBundle\Repository\GoodsRepository
    ...
    manyToOne:
        category:
            targetEntity: Category
            inverseBy: goods
            joinColumn:
                name: category_id
                referencedColumnName: id
    manyToOne:
        brand:
            targetEntity: Brand
            inverseBy: goods
            joinColumn:
                name: brand_id
                referencedColumnName: id
    lifecycleCallbacks: {  }

category.orm.yml

Application\Sonata\MallBundle\Entity\Category:
    type: entity
    table: category
    repositoryClass: Application\Sonata\MallBundle\Repository\CategoryRepository
    ...
    oneToMany:
        goods:
            targetEntity: Goods
            mappedBy: category
    lifecycleCallbacks: {  }

Someone please help, any help appreciated.

Originally created by @ghost on GitHub (Jun 8, 2016). Originally assigned to: @guilhermeblanco on GitHub. Hi, I'm learning symfony2 about sonata-admin-bundle; There are three tables `goods`、`category` and `brand`, I want to show or edit category.name and brand.name in the backend page(goods listView),it will be very convenient for administrator to manage them; ![error_01](https://cloud.githubusercontent.com/assets/17719629/15898814/3b52cf7a-2dcc-11e6-8feb-78233cbfdf7d.jpg) ![error_02](https://cloud.githubusercontent.com/assets/17719629/15898824/422de190-2dcc-11e6-9f84-47028898861f.jpg) It shows category.name is built with "many-to-one" relation successfuly, and the second relation between brand and goods is not work I have two questions: 1、Is the "yml" file just can contain one "many-to-one" relationship? 2、If Iwant to manage the goods info in one page,(please refer the picture),what should I do? Here is some code below: **brand.orm.yml** ``` Application\Sonata\MallBundle\Entity\Brand: type: entity table: brand ... oneToMany: goods: targetEntity: Goods mappedBy: brand lifecycleCallbacks: { } ``` **goods.orm.yml** ``` Application\Sonata\MallBundle\Entity\Goods: type: entity table: goods repositoryClass: Application\Sonata\MallBundle\Repository\GoodsRepository ... manyToOne: category: targetEntity: Category inverseBy: goods joinColumn: name: category_id referencedColumnName: id manyToOne: brand: targetEntity: Brand inverseBy: goods joinColumn: name: brand_id referencedColumnName: id lifecycleCallbacks: { } ``` **category.orm.yml** ``` Application\Sonata\MallBundle\Entity\Category: type: entity table: category repositoryClass: Application\Sonata\MallBundle\Repository\CategoryRepository ... oneToMany: goods: targetEntity: Goods mappedBy: category lifecycleCallbacks: { } ``` Someone please help, any help appreciated.
admin added the Question label 2026-01-22 14:59:37 +01:00
admin closed this issue 2026-01-22 14:59:38 +01:00
Author
Owner

@guilhermeblanco commented on GitHub (Jun 8, 2016):

Hi,

I wonder why you only partially described your question here, but fully
described your question on StackOverflow. If you are looking for help,
always expose as much information as you can. People that are willing to
help aren't looking to hunt your full description in order to help you.
Remember: You are looking for help, they're not looking to help you.

Anyway, already answered on StackOverflow... you have your manyToOne
described twice in your Goods YAML mapping.

On Tue, Jun 7, 2016 at 11:42 PM, liamyabou notifications@github.com wrote:

First please view the pro from here
http://stackoverflow.com/questions/37692486/how-to-defin-two-many-to-one-relation-on-the-table
[image: 7oqeg]
https://cloud.githubusercontent.com/assets/17719629/15882031/e98888a0-2d6d-11e6-806c-a163c9fd8fc9.jpg

One relation is builded success,but the other is failed

Could you give me some advices?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/5859, or mute the thread
https://github.com/notifications/unsubscribe/AAMv82FbaRcDHKbxU78EJQuyp25BzaZwks5qJjowgaJpZM4IwkT9
.

Guilherme Blanco
Lead Architect at E-Block

@guilhermeblanco commented on GitHub (Jun 8, 2016): Hi, I wonder why you only partially described your question here, but fully described your question on StackOverflow. If you are looking for help, always expose as much information as you can. People that are willing to help aren't looking to hunt your full description in order to help you. Remember: You are looking for help, they're not looking to help you. Anyway, already answered on StackOverflow... you have your manyToOne described twice in your Goods YAML mapping. On Tue, Jun 7, 2016 at 11:42 PM, liamyabou notifications@github.com wrote: > First please view the pro from here > http://stackoverflow.com/questions/37692486/how-to-defin-two-many-to-one-relation-on-the-table > [image: 7oqeg] > https://cloud.githubusercontent.com/assets/17719629/15882031/e98888a0-2d6d-11e6-806c-a163c9fd8fc9.jpg > > One relation is builded success,but the other is failed > > Could you give me some advices? > > — > You are receiving this because you are subscribed to this thread. > Reply to this email directly, view it on GitHub > https://github.com/doctrine/doctrine2/issues/5859, or mute the thread > https://github.com/notifications/unsubscribe/AAMv82FbaRcDHKbxU78EJQuyp25BzaZwks5qJjowgaJpZM4IwkT9 > . ## Guilherme Blanco Lead Architect at E-Block
Author
Owner

@ghost commented on GitHub (Jun 8, 2016):

@guilhermeblanco I got it, how can I show brand and category (info) in the list?

@ghost commented on GitHub (Jun 8, 2016): @guilhermeblanco I got it, how can I show brand and category (info) in the list?
Author
Owner

@Ocramius commented on GitHub (Aug 23, 2018):

Closing here - question was already answered.

@Ocramius commented on GitHub (Aug 23, 2018): Closing here - question was already answered.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5146