Sunday, 2 June 2013

Self join with a model

Self join with a model

My model is as follows
class SentSms extends AppModel {
var $name = "Sentsms";

var $hasMany =  array(
                    'SentSms1' => array(
                            'className' => 'SentSms',
                            'order'                => 'SentSms1.sql_id DESC',
                                'foreignKey'   => 'parent_key'));
var $belongsTo =  array(
                        'SentSms2' => array(
                                'className' => 'SentSms',
                                'order'                => 'SentSms2.sql_id DESC',
                                'foreignKey'   => 'parent_key'));
}
Code for controller is as follows :
$this->paginate = array('conditions' => array('service' => $this->Session->read('Auth.User.username'), 'momt' => 'MT'),
                                        'limit' => 25,
                                        'recursive' => '1',
                                        'order' => array('sql_id desc')
    );
    $report = $this->paginate('SentSms');
Here simple select query is being executed. I am new to CakePhp and stuck with it all the day.

No comments:

Post a Comment