Search code examples
symfonyeasyadmin

Easy Admin does not show the relationships


  • I am training Symfony 5.2 using the fast track
  • I am at step 9 configuring EASY Admin
  • Easy Admin creates CRUD Controllers one for Conference and one for Comment (a Comment belongs to a Conference)
  • the problem is when I create a new Comment EasyAdmin does not propose me a select list to choose the Conference it belongs to and the creation finishes with a SQL Exception.

Solution

  • I was also stuck in this step for the same reason !! But I found the solution in this link

    In sum, at Admin/CommentCrudController.php, you should add this:

    use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
    use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
    

    and override function configureFields like this:

    public function configureFields(string $pageName): iterable
    {
        return [
            FormField::addPanel('Conference'),
            AssociationField::new('conference')
                ->setRequired(true)
                ->setHelp('help text'),
            FormField::addPanel('Comment'),
            TextField::new('author')
                ->setHelp('Your name'),
            TextEditorField::new('text', 'Comment')
                ->setHelp('help text'),
            EmailField::new('email', 'Email Address')
                ->setHelp('Your valid email address'),
            DateTimeField::new('createdAt'),
            TextField::new('photoFilename')
        ];
    
    }
    

    Now, it should work fine as for me :-)