CakePHP 3: I'm trying to update a foreign key in my table called poi. The foreign table is named poi_types. Unfortunately the DB-Designer named the foreign key poi_type instead of poi_type_id. Cake responds with
Passed variable is not an array or object, using empty array instead
I'm not able to change the relation, because a working application also sends requests to this specific tables.
Any idea, how it is possible to tell CakePHP to accept the value passed via POST as a plain value?
EDIT
The View contains the following field:
<?= $this->Form->input('poi_type', ['options' => $poi_types_select]); ?>
on
$poi = $this->Pois->patchEntity($poi, $this->request->data);
it fails with the above mentioned error. When deleting the input-field everything works as expected.
I changed the foreign ID to poi_type_id and everything works like a charm as well.
Is there any workaround to convince Cake to update this field?
Error Trace:
--------InvalidArgumentException------
⟩ ArrayObject->__construct
CORE/src/ORM/Marshaller.php, line 200
⟩ Cake\ORM\Marshaller->_prepareDataAndOptions
CORE/src/ORM/Marshaller.php, line 103
⟩ Cake\ORM\Marshaller->one
CORE/src/ORM/Marshaller.php, line 221
⟩ Cake\ORM\Marshaller->_marshalAssociation
CORE/src/ORM/Marshaller.php, line 558
⟩ Cake\ORM\Marshaller->_mergeAssociation
CORE/src/ORM/Marshaller.php, line 412
⟩ Cake\ORM\Marshaller->merge
CORE/src/ORM/Table.php, line 1978
⟩ Cake\ORM\Table->patchEntity
APP/Controller/PoisController.php, line 111
⟩ App\Controller\PoisController->add
[internal function]
⟩ call_user_func_array
CORE/src/Controller/Controller.php, line 410
⟩ Cake\Controller\Controller->invokeAction
CORE/src/Routing/Dispatcher.php, line 114
⟩ Cake\Routing\Dispatcher->_invoke
CORE/src/Routing/Dispatcher.php, line 87
⟩ Cake\Routing\Dispatcher->dispatch
ROOT/webroot/index.php, line 37
TableDefinitions on PoiTypes
class PoiTypesTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
$this->table('poi_types');
$this->hasMany('poi_type_translations');
$this->belongsTo('poi',['foreignKey' => 'poi_type']);
}
TableDefinition on Poi
class PoisTable extends Table
{
/**
* Initialize method
*
* @param array $config The configuration for the Table.
* @return void
*/
public function initialize(array $config)
{
$this->belongsTo('datasets');
$this->hasMany('poi_translations',['foreignKey' => 'poi_id']);
$this->hasOne('poi_types',['foreignKey' => 'id']);
}
$this->request->data['Poi']['poi_type']
Add some code to your question as well. – floriank<?= $this->Form->input('poi_type', ['options' => $poi_types_select]); ?>
on$poi = $this->Pois->patchEntity($poi, $this->request->data);
it fails with the above mentioned error. When deleting the input-field everything works as expected. – Christian Gatzen