简体   繁体   English

与sonata_type_admin的OneToOne关系:字段未链接到管理员

[英]OneToOne relation with sonata_type_admin : field not linked to an admin

I installed the Sonata Admin bundle for manage an online library. 我安装了Sonata Admin捆绑包,用于管理在线图书馆。 I just wanted to link an image to an author . 我只想将image链接到author

The mapping is correct : [Mapping] OK - The mapping files are correct. 映射是正确的:[映射]确定-映射文件是正确的。 [Database] OK - The database schema is in sync with the mapping files. [数据库]确定-数据库架构与映射文件同步。

This is the field of my author entity : 这是我的author实体的字段:

/**
 *
 * @ORM\Column(name="image", type="string", length=255)
 * @ORM\OneToOne(targetEntity="Project\BackendBundle\Entity\Image", cascade={"persist"})
 * @ORM\JoinColumn(nullable=false)
 */
private $image;

I create an Admin class for each entity : 我为每个实体创建一个Admin类:

AuthorAdmin.php AuthorAdmin.php

class AuthorAdmin extends Admin
{
    // Fields to be shown on create/edit forms
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('name', 'text', array('label' => 'Author name'))
            ->add('image', 'sonata_type_admin')
        ;
    }

    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('name')
        ;
    }

    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('name')
        ;
    }
}

But i always have this message : 但是我总是有这样的消息:

The current field image is not linked to an admin. 当前字段image未链接到管理员。 Please create one for the target entity : `` 请为目标实体创建一个:

The admins are set in the admin.yml : 管理员在admin.yml中设置:

services:
    sonata.admin.author:
        class: Project\BackendBundle\Admin\AuthorAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Content", label: "Author" }
        arguments:
            - ~
            - Project\BackendBundle\Entity\Author
            - ~

    sonata.admin.image:
        class: Project\BackendBundle\Admin\ImageAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Content", label: "Image" }
        arguments:
            - ~
            - Project\BackendBundle\Entity\Image
            - 'SonataAdminBundle:CRUD'

I followed all the documentation but now I don't see the problem. 我遵循了所有文档,但现在看不到问题了。

Your mapping is not correct. 您的映射不正确。 There should not be such line. 不应有这样的界线。

@ORM\Column(name="image", type="string", length=255)

@ORM\\Column overrides @ORM\\OneToOne and Doctrine sees this field as simple field - not as association. @ORM\\Column覆盖@ORM\\OneToOne ,Doctrine将此字段视为简单字段-而不是关联。

http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-onetoone http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-onetoone

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM