2012-08-09 41 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