I'm trying to save a data from a multiple select. This data is relacioned where "Request" hasMany "Requestc". The foriegnKey is "request_id"
My Controller:
if ($this->request->is('post')) {
$solicitacao = $this->Request->save($this->request->data['Request']);
//Verifica se a request foi salva e se sim, salva quais as certidões foram pedidas na tabela requests_certidoes
if(!empty($solicitacao)) {
$this->request->data['Requestc']['request_id'] = $this->Request->id;
// debug($this->request->data);
$this->Request->Requestc->saveAll($this->request->data);
}
}
This is my data from $this->request->data
:
array(
'Request' => array(
'motivo' => 'Licitação',
'nome_licitacao' => '',
'data_pregao' => '',
'nome_cliente' => '',
'outros' => ''
),
'Requestc' => array(
'caminho' => array(
(int) 0 => '1',
(int) 1 => '3'
),
'request_id' => '60'
)
)
And that's the error:
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'
SQL Query: INSERT INTO societario
.requests_certidoes
(caminho
, request_id
) VALUES (Array, 62)
Thanks for all
You need to modify the posted data so that it looks like this:
If your relations are properly set-up, you probably don't have to add request_id;
See the documentation: Saving Related Model Data (hasOne, hasMany, belongsTo)
However, if
Requestc.caminho
stores theid
ofCertificates
, this seems to be a HABTM relation;Request --> HABTM --> Certificate
, in which case the join-table should be calledcertificates_requests
and contain the columnsrequest_id
andcertificate_id
. See the Model and Database Conventions