2

私は2つのテーブルの顧客と顧客計画を持っています

顧客テーブルID名1John2 Deol 3 test3 4 test4

カスタマープランテーブルidcust_idstatus 1 2 0 2 3 1 3 4 1

すべての顧客IDを取得したいのですが、プランID(存在する場合)を実行してすべてのデータを取得します

 $criteria->join ='where t.id NOT IN (select cust_id from customer_plan) or t.id in (select customer_id from customer_plan  where foblu_customer_plan.babytel_status = 0)';

これにより、顧客テーブルのIDを取得しますが、両方のテーブルの一意のIDを取得したい

4

1 に答える 1

1

Customer と CustomerPlan の間に関係を作成します。モデルリレーション機能でリレーションを作成できます。

Public function relations()
{
   return array(
      'customerPlan' => array(self::HAS_MANY, 'CustomerPlan', 'cust_id'),
   );
}

この関係を使用して、関連するレコードを見つけます。

$criteria->with = array('customerPlan');

Customer モデルのリレーショナル レコードを取得します。

$customer->customerPlan
于 2012-10-01T08:27:55.347 に答える