I have the following Model structure:
Models:
- Opening
- Application
- Applicant
- Group
The first three was created on initial setup of the application, with Groups added via the bake script afterwards.
Model associations:
- Applicant hasMany Application
- Application hasMany Applicant
- Application belongsTO Opening
- Opening hasMany Application
- Opening belongsTo Group
- Group hasMany Opening (added after bake script ran)
I am trying to retrieve data in the Application model but I'm having some issues. I can't seem to get to the Group table. I keep getting told the column I'm looking for doesn't exist. My query:
$options = array(
'fields' => array(
'Application.applicant_id',
'Application.opening_id',
'Application.value_1',
'Application.date',
'Applicant.first_names',
'Applicant.surname',
'Applicant.gender',
'Applicant.id_number',
'Opening.title',
'Group.group_xs',
'Group.group_name'
),
'recursive' => -1,
'contain' => array(
'Applicant',
'Opening.Group',
),
'conditions' => array(
'Applicant.id' => $applicant_id,
'Opening.id' => $opening_id
)
);
$result = $this->find('all', $options);
Error message:
Column not found: 1054 Unknown column 'Group.group_xs' in 'field list'
I have tried so many different variations of that, it's not even funny. I've tried both with and without 'recursive', with 'recursive' => -1, 0, and 1. I also tried the below variations on the 'contain' key, among many others.
'contain' => array(
'Applicant',
'Opening' =>array('Group')
),
'contain' => array(
'Applicant',
'Opening',
'Group'
),
'contain' => array(
'Group'
),
I load the Containable behavior at the top of my Application model as follows:
public $actsAs = array('Containable' => array('recursive' => true,'autofields' => true));
Can anyone please help. What is going on here?