2015-10-03 119 views
1

我有2個實體:學說2關聯映射錯誤

Brs\UserBundle\Entity\User: 
type: entity 
table: user 
repositoryClass: Brs\UserBundle\Entity\UserRepository 
id: 
    id: 
     type: integer 
     generator: { strategy: AUTO } 
fields: 
    username: 
     type: string 
     length: 50 
    fname: 
     type: string 
     length: 30 
    lname: 
     type: string 
     length: 30 
    email: 
     type: string 
     length: 75 
    mobile: 
     type: string 
     length: 20 
    active: 
     type: boolean 
    mentor: 
     type: boolean 
    roll: 
     type: string 
     length: 10 
    profitPercentage: 
     type: string 
     length: 10 
    initialized: 
     type: datetime 
    password: 
     type: string 
     length: 255 
oneToMany: 
    requests: 
     targetEntity: Brs\FundingBundle\Entity\Request 
     mappedBy: requests 

和:

Brs\FundingBundle\Entity\Request: 
type: entity 
table: null 
repositoryClass: Brs\FundingBundle\Entity\RequestRepository 
id: 
    id: 
     type: integer 
     id: true 
     generator: 
      strategy: AUTO 
fields: 
    amount: 
     type: integer 
    status: 
     type: integer 
    datetime: 
     type: datetime 
    note: 
     type: string 
     length: 255 
    approval: 
     type: boolean 
manyToOne: 
    user: 
     targetEntity: Brs\UserBundle\Entity\User 
     inversedBy: user 
lifecycleCallbacks: { } 
在BRS \ FundingBundle \實體\請求

我的財產申報:

private $user; 

and in Brs \ FundingBundle \ Ent兩者均\用戶:

我已經財產申報:

private $requests; 

當我運行:

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

我得到以下結果:

Updating database schema... 
Database schema updated successfully! "3" queries were executed 

這似乎很好,這創建請求表並將user_id外鍵添加到它,這是我想要的。

但是我已經仔細考慮了Doctrine 2 association mapping的文檔,我似乎無法自信地理解反相,擁有和映射的邏輯。

如果有人可以解釋這個問題與我上面的例子徹底它將不勝感激。

所以在這種情況下,用戶有很多請求。

在此先感謝。

回答

0

閱讀this

大概使用註釋會更方便。