Hi,
every paper, every list, game or test called in our school material.
Every material included competencies.
In add or edit mode I want link the competencies to the material.
in MaterialsTable.php
$this->belongsToMany(‘Competencies’, [
‘className’=>‘Competencies’,
‘through’ => ‘MaterialsToCompetencies’
]);
in CompetenciesTable
$this->belongsToMany(‘Materials’, [
‘className’=>‘Materials’,
‘through’ => ‘MaterialsToCompetencies’
]);
in MaterialsToCompetenciesTable
public function initialize(array $config)
{
$this->belongsTo(‘Competencies’);
$this->belongsTo(‘Materials’);
}
And now in MaterialsController edit I try this…
$compsin = $this->MaterialsToCompetencies->find(‘list’,[‘contain’=>[‘Competencies’=>[‘Parents’]],‘keyField’ => ‘id’,‘valueField’ => ‘label’, ‘conditions’=>[‘MaterialsToCompetencies.material_id’=> $material->id]]);
$comps = $this->Materials->Competencies->find(‘list’,[‘contain’=>[‘Parents’],‘keyField’ => ‘id’,‘valueField’ => ‘label’, ‘conditions’=>[‘Competencies.subject_id =’=> $material->subject_id,‘Competencies.row >’=>1]])->order(‘Competencies.row ASC’)->order(‘Competencies.col ASC’);
$compsin will be the Competencies for one Material in the multiselect field.
$comps worked well and show me all possible competencies for this subject which the material is part from.
in MaterialsToCompetencies.php Entity
protected function _getLabel()
{
return $this->_properties[‘content’];
}
But valueField won’t show my the content of Cometencies or Material (both tables have a content field)
Did anybody have a new approach?
Cheers,
Marc