symfony 外键一对多

发布于 2024-11-09 08:35:47 字数 1742 浏览 3 评论 0原文

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

架构.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

I have two tables A (Utenti) e B (Dispositivi); on B there is a foreign key to A (one Utente->many Dispositivi). I used symfony admin generator. Can I generate a link for each Utente that list me all the related Dispositivi in the Dispositivi view. Is it possible this?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南冥有猫 2024-11-16 08:35:47

以下是学说代码的一个很好的参考:

http://redotheweb .com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/
(特别是如果使用 fou 来推动的话。)

首先,在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 ?>

Here is a good reference for doctrine code:

http://redotheweb.com/2008/07/08/comparing-propel-doctrine-and-sfpropelfinder/
(especially if fou are used to propel.)

First, add a partial in the generator.yml file.

Then do something like this:

<?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 ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文