2012-08-09 39 views
0

我试图合并两个实体(用户和学生)来创建一个单一的形式,下面是我的ORM文件错误上试图Symfony的合并两种形式(entites的)2

Ens\JobeetBundle\Entity\User: 
    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: Ens\JobeetBundle\Entity\Student 
     mappedBy: user 

Ens\JobeetBundle\Entity\Student: 
    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: Ens\JobeetBundle\Entity\User 
     joinColumn: 
     name: user_id 
     referencedColumnName: user_id 

创建实体和更新方案做工精细,

php app/console doctrine:generate:entities EnsJobeetBundle 

php app/console doctrine:database:update --force 

但试图生成CRUD

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中的两个表单?

任何帮助将非常感激......

回答

0

这是因为CRUD生成器不支持的ID是定制的,像student_id数据等... 见code。如下所示,如果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; 
} 
+0

这些干将中已存有每班 – user1583629 2012-08-09 03:52:29

+0

我有edi我的答案 – Mick 2012-08-09 10:36:34