【问题标题】:Retrieving Records Based On Field In Related Model根据相关模型中的字段检索记录
【发布时间】:2023-03-27 16:39:01
【问题描述】:

我有一个员工表,其状态为活动、新和已辞职。在我的应用程序下拉菜单中,我有所有 3 种不同的状态,即活跃、新和辞职,现在我想链接到每个不同的状态,即当我点击活跃时,它只显示员工表中的活跃用户。

请不要将状态表链接到员工表。

提前谢谢你。

【问题讨论】:

    标签: cakephp


    【解决方案1】:
            $records = $this->Employee->find('all', array(
                'recursive' => -1,
                'joins' => array(
                    array(
                    'table' => 'status',
                    'alias' => 'Status',
                    'type' => 'INNER',
                    'conditions' => 'Employee.status = Status.id'
                    )
                ),
                'fields' => array('Employee.field1', 'Employee.field2'),
                'conditions' => array('Status.id' => 'your_status_id'),
            ) 
            );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2014-02-18
      • 1970-01-01
      相关资源
      最近更新 更多