2011-05-23 85 views
2

我有兩個表A(Utenti)e B(Dispositivi);在B上有一個A的外鍵(一個Utente-> many Dispositivi)。我使用了symfony管理生成器。我可以爲每個Utente生成一個鏈接,它列出Dispositivi視圖中的所有相關Dispositivi。這可能嗎?symfony外鍵一對多

的schema.yml

Dispositivi: 
    connection: doctrine 
    tableName: dispositivi 
    columns: 
    id_dispositivo: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    device_id: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    tipo: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    utente_fk: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    relations: 
    Utenti: 
     local: utente_fk 
     foreign: id_utente 
     type: one 
Utenti: 
    connection: doctrine 
    tableName: utenti 
    columns: 
    id_utente: 
     type: integer(4) 
     fixed: false 
     unsigned: false 
     primary: true 
     autoincrement: true 
    username: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    password: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    tipo: 
     type: string(255) 
     fixed: false 
     unsigned: false 
     primary: false 
     notnull: true 
     autoincrement: false 
    relations: 
    Dispositivi: 
     local: id_utente 
     foreign: utente_fk 
     type: many 
    Servizi: 
     local: id_utente 
     foreign: utente_fk 
     type: many 

回答

1

這裏是教義碼的良好參考:

http://redotheweb.com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/ (尤其是如果缶被用於推進。)

首先,添加的部分在generator.yml文件。

然後做這樣的事情:

<?php 
    $dispositivis = $utente->Dispositivis; 
?> 

<?php foreach ($dispositivis as $d): ?> 
    <?php echo link_to($d->getTipo(), 'module_name/action_name?id='. $d->getIdDispositivo()) ?><br /> 
<?php endforeach ?> 
+0

我這樣做。我有相關的dispositivis foregn鍵。我真正的問題是我無法列出所有Utente相關Dispositivis。我嘗試dispositivo/list?id_dispositivo = 1,但不起作用。換句話說,我想在生成的後端的dispositivis視圖中通過它們的id來過濾dispositivis。我希望你明白我在說什麼 – Omega 2011-05-24 08:43:44

+0

你將不得不看看lib/filters並在那裏做出改變。這可能有所幫助:http://www.prettyscripts.com/framework/symfony/symfony-customize-admin-generator-filter – Kevin 2011-05-25 02:52:30