EasyAdminBundle
EasyAdminBundle copied to clipboard
Association Field: error when having a nested one-to-many relationship
Describe the bug I want to use the Association Field for INDEX and DETAIL on a nested one-to-many relationship, and I got this error: "Can't get a way to read the property "id" in class "Doctrine\ORM\PersistentCollection"." What I was expected was that the AssociationField would be rendered as the count of the relationship.
To Reproduce
- Suppose we have 3 entities:
class Blog {
#[ManyToOne(targetEntity: Album::class, inversedBy: 'blogs')]
private $album;
}
class Album {
#[OneToMany(mappedBy: 'album', targetEntity: Blog::class)]
private $blogs;
#[OneToMany(mappedBy: 'album', targetEntity: Image::class)]
private $images;
}
class Image {
#[ManyToOne(targetEntity: Album::class, inversedBy: 'images')]
private $album;
}
- And then in the
BlogCrudController:
class BlogCrudController extends AbstractCrudController {
public function configureFields(string $pageName): iterable
{
return [AssociationField::new('album.images)->setCrudController(ImageCrudController::class)];
}
}
(OPTIONAL) Additional context
- The issue comes from the
AssociationConfigurator, I have fixed it on my project by decorating the AssociationConfigurator, but I would like to fix it in EasyAdmin