Berikut adalah cara join manual selain menggunakan relationship pada model , tapi itu tergantung bagaimana style anda dalam mengcoding, selamat belajar
Howto
1. Saya punya database (SQL Server 2005) dengan Spec berikut (contoh) :
table : 1. tr_client // transaction table
field : - id [PK]
- id_client // this data refers to table ms_client
- transaction
2. ms_client // base table as master client
- id_client [PK]
- name
- address
Model for tr_client without relationship (standart model) :
<?php
class tr_client extends AppModel
{
var $name = 'tr_client';
var $useDBConfig = 'default';
var $useTable = 'tr_client';
var $primaryKey = array('id');
}
?>
2. Basic Statement Join Code :
'joins' => array(
array('table' => 'table_join',
'alias' => 'alias',
'type' => 'left/right',
'foreignKey' => false/true,
'conditions'=> array('condition here'))),
3. How to Query
$data = $this->tr_client ->find('all', array(
'field' => array(
'tr_client.transaction,
'master_client.name'),
'joins' => array(
array('table' => 'ms_client ',
'alias' => 'master_client',
'type' => 'left',
'foreignKey' => true,
'conditions'=> array('
tr_client.id_client = master_client.id_client
'))),
'limit' => 10,
'conditions' => array('tr_client.transaction' => 'approve'));
look at the green and yellow mark, you can learn it.
hope's this help :D
Post a Comment
Harap gunakan bahasa yang baik dan sopan, terima kasih