symfony外键一对多
问题描述:
我有两个表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
答
这里是教义码的良好参考:
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 ?>
我这样做。我有相关的dispositivis foregn键。我真正的问题是我无法列出所有Utente相关Dispositivis。我尝试dispositivo/list?id_dispositivo = 1,但不起作用。换句话说,我想在生成的后端的dispositivis视图中通过它们的id来过滤dispositivis。我希望你明白我在说什么 – Omega 2011-05-24 08:43:44
你将不得不看看lib/filters并在那里做出改变。这可能有所帮助:http://www.prettyscripts.com/framework/symfony/symfony-customize-admin-generator-filter – Kevin 2011-05-25 02:52:30