Cakephp,Retreive Data for HABTM Models using conditional find [英] Cakephp, Retreive Data for HABTM Models using conditional find

查看:188
本文介绍了Cakephp,Retreive Data for HABTM Models using conditional find的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有2种型号:Project&与HABTM关系绑定的类别。
我想从项目控制器执行搜索,可以执行以下操作:

 查找所有DISTINCT Project.scedule WHERE Category.slug!='uncategorised'

续集专家。



我设法做的是检索所有不属于类别未分类到数组的项目,但我不确定如何重新搜索DISTINCT的数组结果Project.schedule values (需要填写表格下拉)



我希望我

在回答这个问题之前,我建议您阅读 HABTM在CAKEPHP的食谱,那么你可以自己完成这样的工作。

  $ this-> Project-> bindModel(array(
'hasOne'=> array(
'CategorysProject',
'FilterCategory'=> array(
'className'=>'Category',
'foreignKey'=> false,
'conditions'=> array('FilterCategory.id = CategorysProject.category_id')
))));
$ this-> Project-> find('all',array(
'fields'=> array(DISTINCT(Project.scedule)),
'conditions'=> ; array('FilterCategory.slug!='=>'uncategorised')
));


There are 2 Models: Project & Category that are bind with HABTM relationship. I would like to perform a search from projects controller that can do the following:

FIND all DISTINCT Project.scedule WHERE Category.slug != 'uncategorised'

Apologies for the syntax, I'm no sequel expert.

What I have managed to do is to retrieve all projects that do not belong to Category uncategorised into an array however I'm not sure as to how to search again the array result for DISTINCT Project.schedule values (needed to fill out a form drop down)

I hope I made myself clear.

解决方案

Before answer this question,again I suggest you to read the HABTM in cookbook of CAKEPHP carefully,then you can finish jobs like this yourself.

$this->Project->bindModel(array(
'hasOne' => array(
    'CategorysProject',
    'FilterCategory' => array(
        'className' => 'Category',
        'foreignKey' => false,
        'conditions' => array('FilterCategory.id = CategorysProject.category_id')
))));
$this->Project->find('all', array(
    'fields' => array(DISTINCT (Project.scedule)),
    'conditions'=>array('FilterCategory.slug !='=>'uncategorised')
));

这篇关于Cakephp,Retreive Data for HABTM Models using conditional find的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆