我有三个表user_log
,user
和designation
。
在这里,我将记录user_log
表中的所有记录,并且也应该显示designation->name
。但user_log
与designation
TABLE没有关系。只有user
表具有designation->id
。 user_log
有user->id
。
如何获取designation->name
和user_log
数据,
user_log
和user
之间的关系var $belongsTo = array(
'loginUser' => array(
'className' => 'User',
'foreignKey' => 'user'
)
);
This is what I have now as a data `array()`,
Array
(
[0] => Array
(
[ActionLog] => Array
(
[id] => 1
[action] => CommitteesController->delete
[user] => 29
[remark] => id-548
[created] => 2018-09-27 14:21:32
[status] => 1
)
[loginUser] => Array
(
[id] => 29
[company_id] => 2
[username] => admin
[password] => 20b90f704be7df945d2ede3fac7fe29b1765f4ae
[user_type] => 0
[designation_id] => 5
[name] => Super Admin user
[address] =>
[mobile_number] =>
[email] => admin1@gmail.com
[uuid] => 11cb016ea2cfa61161b6d85aa1e42f98c6a3829f
[is_active] => 1
[is_director] => 0
[is_new_user] => 0
[office_phone] =>
[group_id] => 1
)
)
function index(){
$search = null;
$dateRange =null;
if(!empty($_POST['search'])){
$search = array('ActionLog.'.$_POST['column'].' LIKE' => '%'.$_POST['field'].'%');
//IF DATE AVAILABLE
if(!empty($_POST['startDate']) && !empty($_POST['endDate'])){
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$dateRange = array("ActionLog.created between ? and ?"=>array($startDate,$endDate));
$search = array_merge($search,$dateRange);
}
}
$this->paginate = array(
'conditions' => $search,
'limit' => 10
);
$data = $this->paginate('ActionLog');
$this->set('logs', $data);
}
如何获取与designation
相关的user
数据?