Now that we are narrowing down the problem area, I put back some of my original code to replace the BTM example code that I was using.
In the controller, I put back the Unit find code:
// $units = $this->Users->Units->find(‘list’);
$units = $this->Users->Units->find(‘list’, [
‘keyFields’ => ‘id’,
‘valueField’ => ‘description’,
‘order’ => array(‘Units.description’ => ‘asc’),
‘limit’ => 200
]);
In the template, I change back how the field is presented. There is some code in there to enable/disable the multi select field based on the role field but that is not really the issue. Here is the change:
// echo $this->Form->control(‘units._ids’, [‘options’ => $units]);
echo $this->Form->control(‘units._id’, [
‘options’ => $units,
‘label’ => false,
‘multiple’ => true,
‘id’ => ‘upick’,
[‘disabled’]
]);
I am back to having the unit descriptions rather than the id and I can select multiple units. Here is what comes back:
getData():
[
‘name’ => ‘test’,
‘username’ => ‘test’,
‘password’ => ‘aaaaaa’,
‘role’ => ‘M’,
‘units’ => [
‘_id’ => [
(int) 0 => ‘2’,
(int) 1 => ‘4’
]
],
‘email’ => ‘’
]
patchEntity():
object(App\Model\Entity\User) {
'name' => 'test',
'username' => 'test',
'password' => '$2y$10$hzrrgEtzn0ZYmBLSeH8fg.3FXXbvhyHpTAWOBJqBqOTi3pJcQ77vm',
'role' => 'M',
'units' => [
(int) 0 => object(App\Model\Entity\Unit) {
'[new]' => true,
'[accessible]' => [
'description' => true,
'census' => true,
'active' => true,
'unit_type_id' => true,
'unit_type' => true,
'beds' => true,
'users' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => true,
'[errors]' => [
'description' => [
'_required' => 'This field is required'
]
],
'[invalid]' => [],
'[repository]' => 'Units'
}
],
'email' => '',
'[new]' => true,
'[accessible]' => [
'name' => true,
'username' => true,
'password' => true,
'role' => true,
'email' => true,
'passkey' => true,
'timeout' => true,
'units' => true
],
'[dirty]' => [
'name' => true,
'username' => true,
'password' => true,
'role' => true,
'units' => true,
'email' => true
],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => true,
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Users'
}
Because of the error shown, If I change the description field to optional in the UnitsTables file to see what would happen. I get this:
object(App\Model\Entity\User) {
'name' => 'test',
'username' => 'test',
'password' => '$2y$10$pTWzlSTnVU8w5z5bmRF2jewVdzD22H0aB.gQpiZpu9r9Xuu/k4zlm',
'role' => 'M',
'units' => [
(int) 0 => object(App\Model\Entity\Unit) {
'[new]' => true,
'[accessible]' => [
'description' => true,
'census' => true,
'active' => true,
'unit_type_id' => true,
'unit_type' => true,
'beds' => true,
'users' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => false,
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Units'
}
],
'email' => '',
'[new]' => true,
'[accessible]' => [
'name' => true,
'username' => true,
'password' => true,
'role' => true,
'email' => true,
'passkey' => true,
'timeout' => true,
'units' => true
],
'[dirty]' => [
'name' => true,
'username' => true,
'password' => true,
'role' => true,
'units' => true,
'email' => true
],
'[original]' => [],
'[virtual]' => [],
'[hasErrors]' => false,
'[errors]' => [],
'[invalid]' => [],
'[repository]' => 'Users'
}
But this throws an error in the save() process. Not sure what made it crash but units does not look like it’s correct after the patch.