SELECT admin.username,user_data.username FROM leaves
,users as admin,users as user_data WHERE admin.id
=admin_id
and user_data.id=user_id
I want this type of join as shown above query.
We have created code, see below:-
class LeavesTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('leaves');
$this->displayField('id');
$this->primaryKey('id');
$this->belongsTo(‘Users’, [
‘propertyName’=>‘admindata’,
‘foreignKey’ => ‘admin_id’,
]);
$this->belongsTo(‘Users’, [
‘propertyName’=>‘userdata’,
‘foreignKey’ => ‘user_id’,
]);
class UsersTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('users');
$this->displayField('username');
$this->primaryKey('id');
$this->hasMany('Leaves', [
'foreignKey' => 'user_id'
]);