我正在尝试合并两个实体(用户和学生)以创建一个表单,下面是我的orm文件
EnsJobeetBundleEntityUser:
type: entity
table: abc_user
id:
user_id: { type: integer, generator: { strategy: AUTO } }
fields:
username: { type: string, length: 255, notnull: true, unique: true }
email: { type: string, length: 255, notnull: true, unique: true }
password: { type: string, length: 255, notnull: true }
enabled: { type: boolean }
oneToOne:
student:
targetEntity: EnsJobeetBundleEntityStudent
mappedBy: user
EnsJobeetBundleEntityStudent:
type: entity
table: abc_student
id:
student_id: { type: integer, generator: { strategy: AUTO } }
fields:
first_name: { type: string, length: 255, notnull: true }
middle_name: { type: string, length: 255 }
last_name: { type: string, length: 255, notnull: true }
oneToOne:
user:
targetEntity: EnsJobeetBundleEntityUser
joinColumn:
name: user_id
referencedColumnName: user_id
创建实体和更新方案工作正常,
php app/console doctrine:generate:entities EnsJobeetBundle
php app/console doctrine:database:update --force
但是当试图生成污垢时
php app/console generate:doctrine:crud --entity=EnsJobeetBundle:Student
我最终出现以下错误,
[RuntimeException]
The CRUD generator expects the entity object has a primary key field named "id" with a getId() method.
有谁知道如何摆脱这个? 如何在Symfony 2中合并两个表单?
任何帮助将不胜感激...
这是因为 CRUD 生成器不支持自定义的 id,例如student_id等...请参阅代码。如下所示,如果 id 不在实体中,则会出现运行时异常。
//....
if (!in_array('id', $metadata->identifier))
{
throw new RuntimeException('The CRUD generator expects the entity object has a primary key field named "id" with a getId() method.');
}
//....
您必须重命名模型中的自定义 ID:
用户:
protected $id;
public function getId()
{
return $this->id;
}
学生:
protected $id;
public function getId()
{
return $this->id;
}