我有实体1和实体2。
在Entity1的表单中,我显示了一个选项列表,其中选项是从Entity2混合而来的。
我希望将所选选项保存为Entity1表中列内的字符串,但不希望在表之间创建任何关系。
我该怎么做?
class Entity1 {
/**
* @ORM\Column(type="string")
*/
private $historico;
}
class Entity2 {
/**
* @ORM\Column(type="string")
*/
private $description;
}
entity1formtype.php文件
$builder->add('historico', EntityType::class, [
'class' => Entity2::class,
'choice_label' => 'description',
'choice_value' => 'description',
'placeholder' => ''
]);
选项显示良好,但提交时会出现以下错误:
Expected argument of type "string", "App\Entity\Entity2" given.
如果使用'mapped'=>false,则输入提交为空。
如何将实体对象转换为字符串?
帮助一个symfony noob:)