A Baked edit function on the members table dies with exception inside ->patchEntity just before save with the following error:
Argument 1 passed to Cake\ORM\Marshaller::merge() must implement interface Cake\Datasource\EntityInterface, integer given, called in E:\membership\vendor\cakephp\cakephp\src\ORM\Marshaller.php on line 594 and defined [CORE\src\ORM\Marshaller.php, line 416]
The Baked code:
public function edit($id = null)
{
$member = $this->Members->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
debug($member);
debug($this->request->data);
$member = $this->Members->patchEntity($member, $this->request->data);
debug($member);
if ($this->Members->save($member)) {
$this->Flash->success(__('The member has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The member could not be saved. Please, try again.'));
}
}
$this->set(compact('member'));
$this->set('_serialize', ['member']);
$memberTypes = TableRegistry::get('MemberTypes');
$query = $memberTypes->find('list');
$data = $query->toArray();
$this->set('memberTypes', $data);
}
I've added three debugging statements. Two are just prior to the use of ->patchEntitiy, and the third is just after! The output is:
object(App\Model\Entity\Member) {
'id' => (int) 2,
'member_name' => 'Some Name',
'member_address' => 'On Street',
'member_city_state_zip' => 'Some Where, ST 12345',
'member_type' => (int) 2,
'member_first_year' => (int) 1998,
'member_last_paid_year' => (int) 2015,
'member_email' => '[email protected]',
'member_phone' => '975.852.XXXX',
'member_cell' => '975.852.XXXX',
'member_selected' => '1',
'[new]' => false,
'[accessible]' => [
'member_name' => true,
'member_address' => true,
'member_city_state_zip' => true,
'member_type' => true,
'member_first_year' => true,
'member_last_paid_year' => true,
'member_email' => true,
'member_phone' => true,
'member_cell' => true
],
'[dirty]' => [],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Members'
}
[
'id' => '2',
'member_name' => 'Some Name',
'member_address' => 'On Street',
'member_city_state_zip' => 'Some Where, ST 12345',
'member_type' => '2',
'member_first_year' => '1998',
'member_last_paid_year' => '2015',
'member_email' => '[email protected]',
'member_phone' => '975.852.xxxx',
'member_cell' => '975.852.xxxx',
'member_selected' => '1'
]
It looks to me that ->patchEntity is getting an object and an array, but is somehow not getting the right stuff to the Marshaller? Any help would be greatly appreciated.
Thanks in advance for your assistance. GLK
This problem stems from having changed a field name and its type. But I forgot to change the Entity::$_accessablity and the Table::$validator settings and Table::$rules.
Stupid of me, eh? But I sure do wish cakePHP 3.0.7 had actually thrown up a message that indicated the missing field issue and validator tests errors.
Anyway, hope this helps someone else!