2011-08-15 2 views
0

DB에 4 개의 테이블이 있습니다. 가맹점, pay_method, 지출 ans transaction_type.Zend (SE)와 결합하여 쿼리를 수행하려고 시도합니다.

이들은 모두 다른 사람의 외래 키와 user_id, comment 등의 외래 키를 가지고 있습니다. 지출을 제외하고는 모두 ID와 제목을 가지고 있습니다.

고유 한 user_id에 대한 모든 테이블의 모든 정보를 갖도록 노력합니다! 나는 모든이 올바르게 조인 할 수있는 방법

foreach($this->spendings as $s) { 
     var_dump($s->comment); 
} 

을 :

public function getSpendingsForUser($userid) 
{ 
    $mercTable = Engine_Api::_()->getDbTable('merchants', 'spendings'); 
    $mercName = $mercTable->info('name'); 

    $table = Engine_Api::_()->getDbTable('spendings', 'spendings'); 
    $spendName = $table->info('name'); 

    $select = $table->fetchAll(
     $table->select() 
     ->joinLeft($mercName, "$mercName.merchant_id = $spendName.merchant_id", NULL) 
     ->where('user_id = ?', $userid) 
     ->group('spending_id') 
     ); 
    return $select; 

} 

을보기 파일 : 그것을 수행하기위한

, 나는 실행되지 않습니다 약간의 테스트를 시도 user_id의 정보 ???

감사합니다.

답변

1

저희가 도와 드릴 수 있도록 정의하지 않아야합니다. 하지만 조인하기 전에 당신은 아마 ->setIntegrityCheck(false);

$select = $table->fetchAll(
     $table->select() 
     ->setIntegrityCheck(false); 
     ->joinLeft($mercName, "$mercName.merchant_id = $spendName.merchant_id", NULL) 
     ->where('user_id = ?', $userid) 
     ->group('spending_id') 
     ); 

필요 말할 수 있습니다.

+0

확인해 보겠습니다. – clement

+0

@clement 작동 했습니까? – Iznogood

+0

그것으로 더 좋습니다 ;-) Thanks – clement

관련 문제