How to see values of multiple checkbox on hasmany

For a hasMany relationship I cant get the required field to display as a label, instead I get the id value as the label

$availabilityForTutors = $this->Tutors->AvailabilityForTutors->find(‘list’, [
‘conditions’=>array(‘AvailabilityForTutors.tutor_id’=> $id),‘limit’ => 200]);

echo $this->Form->input(‘availabilityForTutors’, [‘multiple’ => ‘checkbox’,‘label’=>$availabilityForTutors->weekday]);

Set the displayField method to the name of the column you want to use as the label. This can be done within the Table class of the association.

public function initialize(array $config) {

         $this->displayField('name');  //  Change this value

You can also set the key value fields in the finders options array as in the code below:

$availabilityForTutors = $this->Tutors->AvailabilityForTutors->find('list', ['keyField' => 'column acting as key', 'valueField' => 'column acting as value', 'conditions'=>array('AvailabilityForTutors.tutor_id'=> $id),'limit' => 200]);

You can read more about the findList options here

1 Like