【问题标题】:Doctrine many-to-many relations with extra field与额外领域的多对多关系学说
【发布时间】:2010-10-11 08:29:19
【问题描述】:

我想加入 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 的号码。我怎么也得到数字字段?没有选择。

【问题讨论】:

    标签: php schema yaml symfony-1.4 doctrine-1.2


    【解决方案1】:

    使用

    ->select('t.number')
    

    喜欢

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

    【讨论】:

    • 不选择你可以加入所有表,但你会从所有 3 个表中获取所有字段
    • like : Doctrine_Query::create()->from('table a')->leftJoin('Vasarlo v')->leftJoin('SzamlaTermekek t');
    • 是的,使用 Symfony:Doctrine_Core::getTable('Szamla')->createQuery('s')->leftJoin('Vasarlo v')->leftJoin('SzamlaTermekek t')-> fetchArray();解决方案是这样的:Doctrine_Query::create()->from('Szamla')->leftJoin('Szamla.Vasarlo v')->leftJoin('Szamla.SzamlaTermekek t')->leftJoin('t.SzamlaTermek szt ON t.id = szt.termek_id AND Szamla.id = szt.szamla_id INDEXBY szt.termek_id');
    猜你喜欢
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多