I am using CakePHP 4.0.3.
My Kids table has 3 fields (nationality_id, language_id, other_language_id) associated with the same tables nationalities
I have them all declared in KidsTable as below:
$this->belongsTo('Nationalities', [
'className' => 'nationalities',
'foreignKey' => 'nationality_id',
]);
$this->belongsTo('Languages', [
'className' => 'nationalities',
'foreignKey' => 'language_id',
]);
$this->belongsTo('OtherLanguages', [
'className' => 'nationalities',
'foreignKey' => 'other_language_id',
]);
And of course they are in accessible in KidEntity:
protected $_accessible = [ ... 'nationality_id' => true, 'language_id' => true, 'other_language_id' => true, 'nationality' => true, 'language' => true, 'other_language' => true, ...
But in Edit view, only Nationality get list of option, the 2 language Select form control get nothing.
The view is at below:
<div class="col-12">
<div class="form-group">
<?= $this->Form->control('nationality_id', ['class' => 'form-control', 'option' => $nationalities, 'empty' => true ]); ?>
</div>
</div>
<div class="col-6">
<div class="form-group">
<?= $this->Form->control('language_id', ['class' => 'form-control', 'option' => $nationalities, 'empty' => true ]); ?>
</div>
</div>
<div class="col-6">
<div class="form-group">
<?= $this->Form->control('other_language_id', ['class' => 'form-control', 'option' => $nationalities, 'empty' => true ]); ?>
</div>
</div>
The weird thing is that, I use the same 3 fields in other view of another Model (Users model, I patch associated data), of course I have to use TableRegistry to locate the tables and get values, I can uses the set of data for all 3 of those fields.
I also tried to use TableRegistry to get data into a variable with different name, still only Select input for Nationality has option.
In some modification of the code, non of the Select input has value at all.
I confused, I still see the values in view (via → set() ), but can’t use. Why ?