带有额外字段的 Doctrine 多对多关系

发布于 2024-09-26 18:42:04 字数 2492 浏览 5 评论 0原文

我想加入 3 张桌子,Szamla、Termek 和 Vasarlo。

这是我的架构:

options:
    collate: utf8_unicode_ci
    charset: utf8

Szamla:
  actAs: [Timestampable]
  columns:
    datum:
      type: timestamp
      notnull: true
    total:
      type: float
      notnull: true
    fizetesi_datum:
      type: date
    fizetesi_ora:
      type: time
    teljesites:
      type: timestamp
    user_id:
      type: int(10)
      notnull: true
    afa:
      type: boolean
      notnull: true
      default: 0
  relations:
    SzamlaTermekek:
      class: Termek
      local: szamla_id
      foreign: termek_id
      refClass: SzamlaTermek

Vasarlo:
  columns:
    nev:
      type: string(255)
      notnull: true
    varos:
      type: string(200)
      notnull: true
    utca:
      type: string(200)
      notnull: true
    zip:
      type: string(10)
      notnull: true
    email:
      type: string(255)
      notnull: true
    orszh:
      type: string(4)
      notnull: true
    krzt:
      type: string(2)
      notnull: true
    telszama:
      type: string(4)
      notnull: true
    telszamb:
      type: string(3)
      notnull: true
  relations:
    Szamlak:
      class: Szamla
      type: many
      local: id
      foreign: user_id
      foreignAlias: Vasarlo

Termek:
  columns:
    nev:
      type: string(255)
      notnull: true
    leiras:
      type: string(500)
      notnull: true
    ar:
      type: float
      notnull: true
    raktar:
      type: string(255)
      notnull: true
      default: Dunaújváros
    raktaron:
      type: integer(4)
      notnull: true
      default: 0
    zarolt:
      type: boolean
      notnull: true
      default: 0
    jotallas:
      type: boolean
      notnull: true
      default: 0
    garancia:
      type: boolean
      notnull: true
      default: 0
    slider:
      type: integer(1)
      notnull: true
  relations:
    SzamlaTermekek:
      class: Szamla
      local: termek_id
      foreign: szamla_id
      refClass: SzamlaTermek

SzamlaTermek:
  columns:
    szamla_id:
      type: integer
      primary: true
    termek_id:
      type: integer
      primary: true
    number:
      type: integer
      notnull: true
      default: 1

查询:

   $query = Doctrine_Core::getTable($table)->createQuery('s');
    $query->leftJoin('Vasarlo v');
    $query->leftJoin('SzamlaTermekek t');
    $result = $query->fetchArray();

结果没问题,但需要 SzamlaTermek 的号码。如何获取数字字段?无需选择。

I want to join 3 table, Szamla, Termek and Vasarlo.

This is my schema:

options:
    collate: utf8_unicode_ci
    charset: utf8

Szamla:
  actAs: [Timestampable]
  columns:
    datum:
      type: timestamp
      notnull: true
    total:
      type: float
      notnull: true
    fizetesi_datum:
      type: date
    fizetesi_ora:
      type: time
    teljesites:
      type: timestamp
    user_id:
      type: int(10)
      notnull: true
    afa:
      type: boolean
      notnull: true
      default: 0
  relations:
    SzamlaTermekek:
      class: Termek
      local: szamla_id
      foreign: termek_id
      refClass: SzamlaTermek

Vasarlo:
  columns:
    nev:
      type: string(255)
      notnull: true
    varos:
      type: string(200)
      notnull: true
    utca:
      type: string(200)
      notnull: true
    zip:
      type: string(10)
      notnull: true
    email:
      type: string(255)
      notnull: true
    orszh:
      type: string(4)
      notnull: true
    krzt:
      type: string(2)
      notnull: true
    telszama:
      type: string(4)
      notnull: true
    telszamb:
      type: string(3)
      notnull: true
  relations:
    Szamlak:
      class: Szamla
      type: many
      local: id
      foreign: user_id
      foreignAlias: Vasarlo

Termek:
  columns:
    nev:
      type: string(255)
      notnull: true
    leiras:
      type: string(500)
      notnull: true
    ar:
      type: float
      notnull: true
    raktar:
      type: string(255)
      notnull: true
      default: Dunaújváros
    raktaron:
      type: integer(4)
      notnull: true
      default: 0
    zarolt:
      type: boolean
      notnull: true
      default: 0
    jotallas:
      type: boolean
      notnull: true
      default: 0
    garancia:
      type: boolean
      notnull: true
      default: 0
    slider:
      type: integer(1)
      notnull: true
  relations:
    SzamlaTermekek:
      class: Szamla
      local: termek_id
      foreign: szamla_id
      refClass: SzamlaTermek

SzamlaTermek:
  columns:
    szamla_id:
      type: integer
      primary: true
    termek_id:
      type: integer
      primary: true
    number:
      type: integer
      notnull: true
      default: 1

The query:

   $query = Doctrine_Core::getTable($table)->createQuery('s');
    $query->leftJoin('Vasarlo v');
    $query->leftJoin('SzamlaTermekek t');
    $result = $query->fetchArray();

The result is ok, but the number from SzamlaTermek needed. How get i the number field too? Without select.

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

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

发布评论

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

评论(1

独孤求败 2024-10-03 18:42:04

使用

->select('t.number')

类似

$query->select('t.number')
       ->leftJoin('Vasarlo v')
       ->leftJoin('SzamlaTermekek t');

use

->select('t.number')

like

$query->select('t.number')
       ->leftJoin('Vasarlo v')
       ->leftJoin('SzamlaTermekek t');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文