views:

52

answers:

1

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.

A: 

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')
));
SpawnCxy
Thank you very much for your answer. It works greatI am trying to understand this method...so that I can use it myself.There seems to be however something else that is weird. After the bindModel I can only perform one query. When I try to perform a second query (similar to the one in your example) it does not do it. I have to re-bindModel again. Does that sound right to you. Does that mean the the bindModel method is valid only for a single query.
ion
Yeah,that's what it should be.However, if you have more than one query to do then there are other simple ways to do this.Just check the manual,try to find you answer by yourself.:)
SpawnCxy
Thanks for the kickoff :)
ion
you're welcome.
SpawnCxy