2010-10-11 93 views
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數量。如何讓我的號碼字段呢?沒有選擇。

回答

0

使用

->select('t.number') 

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

OK,這個工作,但沒有選擇? – turbod 2010-10-11 09:12:17

+0

沒有選擇你可以加入所有表格,但你從所有3個表格 – 2010-10-11 09:17:16

+0

中獲得所有字段,例如:Doctrine_Query :: create() - > from('table a') - > leftJoin('Vasarlo v') - > leftJoin(' SzamlaTermekek t'); – 2010-10-11 09:18:14