Hi all ye thrifty helpers

I'm trying to use the containable behaviour for a somewhat complex
query. I've gotten most of it to work. The only anomaly is that I want
the containable to contain a condition for the actual query. Here's
what I have:

var $hasAndBelongsToMany = array('Module');
var $actsAs = array('Containable');


$result = $this->find('all',array(
 'conditions'=>array('Assessment.disabled'=>0),
 
'fields'=>array('Assessment.id','Assessment.name','Assessment.material_link','Assessment.compliance_id'),
 'contain'=>array('Module'=>array('conditions'=>array('Module.id'=>
$userId))),
 'order'=>'Assessment.id ASC'
));

Here is one of the results

[Assessment] => Array
                (
                    [id] => 1
                    [name] => Test 1
                    [material_link] => link1
                    [compliance_id] =>
                )

            [Module] => Array
                (
                )

        )

The query works, except that I don't want this record to show up at
all. If it had had a module attached then it should show up, otherwise
this record should not return at all.

For what its worth, I previously had it working with the following
query:

$this->bindModel(array('hasOne'=>array('AssessmentsModule')));
$conditions = array('AssessmentsModule.module_id'=>$userId);
$result = $this->find('all',array(
 'conditions'=>array('or'=>$conditions,'Assessment.disabled'=>0),
 
'fields'=>array('Assessment.id','Assessment.name','Assessment.material_link','Assessment.compliance_id'),
 'recursive'=>0,
 'order'=>'Assessment.id ASC'
));

I'm sure there's something small I'm missing, but haven't figured it
out, due to the fact that cake doesn't join this but rather runs it in
2 or so queries.

The reason for all this is that I need to add another condition into
the query from a different model and I'm hoping to use contains to
help me out a little.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to