php - EasyAdminBundle 3:带有实体的集合字段
问题描述
我有两节课:
class Product {
/**
* @ORM\OneToMany(targetEntity=Keyword::class, mappedBy="product")
*/
private $keywords;
}
class Keyword {
/**
* @ORM\Column(type="string", length=255)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity=Product::class, inversedBy="keywords")
*/
private $product;
}
在我定义的产品 CRUD 控制器中:
public function configureFields(string $pageName): iterable
{
yield CollectionField::new('keywords');
}
它正确显示了所有关键字,但是当我尝试保存它时出现错误:
属性路径“keywords”中给出的“App\Entity\Keyword”、“string”类型的预期参数。
是否有可能将这种联系显示为集合?以这种方式管理关键字会容易得多。
解决方案
你需要使用
yield AssociationField::new('keywords');
代替
yield CollectionField::new('keywords');
推荐阅读
- java - 如何用 JTextField 信息替换选中的 JCheckbox
- eclipse - 是否有在 Eclipse 比较视图中的窗格之间切换的快捷方式?
- jms - 通过 Bridge 将消息单元顺序属性从源 ActiveMQ 保留到 Weblogic 队列
- sabre - 响应中缺少 SABER 酒店预订请求 TravelItineraryRead
- python - 使用opencv python检测不完整的圆
- julia - 在 Julia 中使用 GeoStats 包进行克里金插值
- django - Nginx 渲染速度太慢
- powershell - 在 jenkins(windows) 中,powershell ls 管道获取 null
- php - 在 PHPUnit 测试类中使用 Doctrine EntityManager
- java - JavaFX 按键事件