2010-12-12 9 views
0

Doctrine_PagerまたはsfDoctrinePagerを使用してページングを実装するには、クエリで2つ以上のテーブルから複数の列を選択する必要がありますか?複数のテーブルから選択された異なる列のdoctrineまたはsymfonyページャの使用方法?


EDIT1:

OK]をクリックして、今私はネイサンは、以下に説明している方法を行うことができることを考え出しました!私はクエリから特定のデータを取得できなかったので、混乱しました!私は以下のことを説明してみましょう:

これは私のポケベルクエリです:

 $pager = new sfDoctrinePager('sfGuardUser', '5'); 

     $q = Doctrine_Query::create() 
         ->select('u.id, u.username, p.org_name, g.name, l.status') 
         ->from('sfGuardUser u') 
         ->leftJoin('u.Profile p') 
         ->leftJoin('u.Groups g') 
         ->leftJoin('u.LicensedVendors l') 
         ->where('g.name = \'client\''); 

     $pager->setQuery($q); 
     $pager->setPage($request->getParameter('page', 1)); 
     $pager->init(); 

は今私のテンプレートで私はこのように私のsfGuardUserとプロファイルデータを取得することができます。

foreach ($pager->getResults() as $data) { 


      echo $data->username ; //outputs 'username' from sfGuardUser table 
      echo '<br />' ; 
      echo $data->Profile->org_name ; //outputs 'Organization name' from sfGuardUserProfile table 

} 

私が間違ってしようとしていましたプロファイルデータを$data->org_nameで検索し、$data->Profile->org_nameではなく!今、この部分の作業は正しく、ですが、まだ問題があります

私はまだグループ & LicensedVendors $data->Groups->nameまたは$data->LicensedVendors->statusを使用してデータを取得することができません!どちらのエラーも値も表示されません!空の文字列を出力するように見えます。プロファイルデータと同じ値を取得してはいけませんか?私は設定して、クエリをhydrateとき しかし:**Doctrine_Core::HYDRATE_SCALAR**を設定せずに、それらのデータを取得する方法

foreach ($pager->getResults() as $data) { 

     echo $data['u_username']; 
     echo $data['p_org_name']; 
     echo $data['g_name']; 
     echo $data['l_status']; 
} 

$q->setHydrationMode(Doctrine_Core::HYDRATE_SCALAR);

を私が通過するすべてのデータを取得することができますか?私はそれらを取得するために間違っていますグループLicensedVendorsテーブルのデータですか?ここで

は、上記のテーブルのスキーマ定義である:

License: 
    actAs: [Timestampable] 
    tableName: licenses 
    columns: 
    id: 
     type: integer(4) 
     primary: true 
     notnull: true 
     autoincrement: true 
    status: 
     type: enum 
     values: ['approved','pending_admin','pending_client','pending_vendor','rejected'] 
     default: 'pending' 
    client_id: 
     type: integer(8) 
     notnull: true 
    vendor_id: 
     type: integer(8) 
     notnull: true 
    product_desc: 
     type: clob(16777215) 
    supplier_name: 
     type: string(80) 
    other_desc: 
     type: string(50) 
    financial_statement: 
     type: clob 
    relations: 
    VendorUser: 
     class: sfGuardUser 
     local: client_id 
     foreign: id 
     foreignAlias: LicensedVendors 
     onDelete: cascade 
     foreignType: many 
     owningSide: true 
    ClientUser: 
     class: sfGuardUser 
     local: vendor_id 
     foreign: id 
     foreignAlias: LicensedClients 
     onDelete: cascade 
     foreignType: many 
     owningSide: true 


sfGuardUser: 
     actAs: [Timestampable] 
     columns: 
     first_name: string(255) 
     last_name: string(255) 
     email_address: 
      type: string(255) 
      notnull: true 
      unique: true 
     username: 
      type: string(128) 
      notnull: true 
      unique: true 
     algorithm: 
      type: string(128) 
      default: sha1 
      notnull: true 
     salt: string(128) 
     password: string(128) 
     is_active: 
      type: boolean 
      default: 1 
     is_super_admin: 
      type: boolean 
      default: false 
     last_login: 
      type: timestamp 
     indexes: 
     is_active_idx: 
      fields: [is_active] 
     relations: 
     Groups: 
      class: sfGuardGroup 
      local: user_id 
      foreign: group_id 
      refClass: sfGuardUserGroup 
      foreignAlias: Users 

sfGuardUserProfile: 
    actAs: 
    Timestampable: ~ 
    columns: 
    user_id: 
     type: integer 
     notnull: true 
    email: 
     type: string(80) 
     notnull: true 
     unique: true 
    email_new: 
     type: string(80) 
     unique: true 
    firstname: 
     type: string(30) 
    lastname: 
     type: string(70) 
    org_name: 
     type: string(80) 
     notnull: true 

    relations: 
    User: 
     class: sfGuardUser 
     foreign: id 
     local: user_id 
     type: one 
     onDelete: cascade 
     foreignType: one 
     foreignAlias: Profile 




sfGuardGroup: 
    actAs: [Timestampable] 
    columns: 
    name: 
     type: string(255) 
     unique: true 
    description: string(1000) 
    relations: 
    Users: 
     class: sfGuardUser 
     refClass: sfGuardUserGroup 
     local: group_id 
     foreign: user_id 
     foreignAlias: Groups 


EDIT2:私は別の問題として、最初の編集で説明した私の新たな問題を掲載しましたhere

答えて

0

ええ、greg0ireが言った。 This documentation is a bit oldしかし、それはあなたが昔にPropelで必要とするものを示しています。教義に更新する

public function executeList() 
{ 
    $pager = new sfDoctrinePager('Comment', 2); 

    $q = Doctrine_Core::getTable('Comment') 
    ->createQuery('c') 
    ->where('c.author = ?', 'Steve') 
    ->leftJoin('c.Article a') 
    ->andWhere('a.content LIKE ?', '%enjoy%') 
    ->orderBy('c.created_at ASC'); 

    $pager->setQuery($q); 
    $pager->setPage($request->getParameter('page', 1)); 
    $pager->init(); 

    $this->pager = $pager; 
} 

This blog post, "Symfony doctrine pager for two tables"、のようであろう複数の拡張/入り組んだ例を有しています。ああ、それはhis own SO questionへの著者の答えだったようです。

+0

お返事ありがとうございました!それはあなたが上に置く方法で動作するはずです。しばらくの間試した後、私は問題を理解しました。実際には別の方法でデータを取得する必要があります。しかし、問題の編集された部分に精巧に詰め込んだ問題がまだ残っています!あなたはそれを見ることができます:) – med

+0

medhad、あなたの元の質問は明確で、私はそれに明確に答えようとしました。あなたの編集では、それはまったく違うものです。たぶんあなたは新しい質問をするべきです。ページャを設定する前に実際に結合が必要かどうか疑問に思っていますか?ポケベルの結果をループする際に '$ license-> getVendorUser()'を実行できませんか? – Nathan

+0

ネイサン、新しい質問として投稿するのは正しいです!私はちょうど新しいスレッドでそれを聞いて、ここから掻き集めました! * $ license-> getVendorsUser * trueでユーザー(ベンダー)を取得できますが、この場合、クライアントグループ内のすべてのユーザーと、現在のベンダーの対応するライセンスステータスを照会する必要があります。 – med

1

質問がDoctrine_Collectionオブジェクトを返す限り、ページャで使用することはできますか?

+0

こんにちは、実際にあなたは正しいです!しかし、私はページャーからデータを取得する際に問題を抱えていました!私は、結合されたテーブルの列データを取得するために、別のコードを書く必要があることを理解しました。 – med

関連する問題