[Solved]Using Find To Retrieve Records Based On Attribute Of Related Table

Hi all,

I have 3 tables with relations between them as follows:-

Table Client

'orders' => array(self::HAS_MANY, 'Order', 'client_id'),		

Table Order

'client' => array(self::BELONGS_TO, 'Client', 'client_id'),

'orderpayments'=> array(self::HAS_MANY, 'Orderpayment', 'order_id'),

Table Orderpayment

'order' => array(self::BELONGS_TO, 'Order', 'order_id'),

In my controllerclient, I want to create a function which will retrieve all the payments made by a specific client. Is there a way using findAll() which can do this?

How do I refer to the client_id of the table orders which is related to the table orderpayment (see code below)

$payments=Orderpayment::model()->findAll('what to put here=:id', array(':id'=>$clientId));

Hi all,

Forget it. Resolved :)

$payments= Orderpayment::model()->with('order')->findAll('order.id=:id', array(':id'=>$model->id));


Good news …

Maybe post your solution and mark topic as solved, that will surely help someone later ::)

I just posted the solution :) You are right, Luc, will mark it as SOLVED also. Will do it right away