首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >symfony外键一对多

问symfony外键一对多
EN

Stack Overflow用户
提问于 2011-05-23 22:04:49
回答 1查看 590关注 0票数 2

我有两个表A (Utenti) e B ( Dispositivi);在B上有一个指向A的外键(一个Utente->多个Dispositivi)。我使用symfony管理生成器。我是否可以为每个用户生成一个链接,在Dispositivi视图中列出所有相关的Dispositivi。这是可能的吗?

schema.yml

代码语言:javascript
复制
   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
EN

回答 1

Stack Overflow用户

发布于 2011-05-24 13:30:12

这是一个很好的法则代码的参考:

http://redotheweb.com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/ (特别是当fou用于推动的时候)。

首先,在generator.yml文件中添加一个分部。

然后这样做:

代码语言:javascript
复制
<?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 ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6098291

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档