0

I'm building an application with CakePHP on which you can fill in surveys. The problem i came up with is the following:

I have two tables:

Surveys / SurveysUsers (HABTM)

When somebody fills in a survey a record will be made in SurveysUsers and when the Survey is accepted the survey shouldn't be visible anymore. So i want to select the surveys from the surveys table which don't have a record in the SurveysUsers table.

Hope u all can help me!

Thanks

Dwayne

Dwayne
  • 1

1 Answers1

0

Just off the cuff, try this:

$this->Survey->bindModel(array('hasOne'=>array('SurveysUsers')));
$surveys = $this->Survey->find('all',array(
    'conditions'=>array('SurveysUsers.survey_id NOT'=>'Survey.id');
));

The principle is that you bind the habtm model as hasone and then you can use the fields in your conditions. Have a look in the Docs

Gevious
  • 3,214
  • 3
  • 21
  • 42