Reputation: 284
I got dynamic tables so I created 2 models that dynamically. Then I created association of hasOne between them. It works well reading the Data, but I get this error when I use saveAll() Undefined index: NodeData [CORE/cake/libs/model/model.php, line 1702]
I got the code for Node and NodeData models
class Node extends PostgresAppModel {
var $name = 'Node';
var $useDbConfig = 'pgdata';
var $useTable = false;
var $recursive = 0;
--
class NodeData extends PostgresAppModel {
var $name = 'NodeData';
var $useDbConfig = 'pgdata';
var $useTable = false;
var $primaryKey = 'node_id';
var $recursive = 0;
In the controller I configured the action:
function edit($network_id = null, $variation_id = null, $node_id = null)
$prefix = $this->Network->getNetworkPrefix($network_id);
if (!empty($this->data)) {
$this->Node->setSource(sprintf('%s_node', $prefix));
$this->NodeData->setSource(sprintf('%s_node_data', $prefix));
$this->Node->bindModel(array(
'hasOne' => array(
'NodeData' => array(
'foreignKey' => 'node_id',
'className' => 'NodeData',
)
)
));
$this->data['NodeData']['id'] = $this->data['NodeData']['node_id'];
if ($this->Node->saveAll($this->data)) {
I debug the line in model.php, but can't get why $this->{$type}[$association] gives the error
$values[$this->{$type}[$association]['foreignKey']] = $this->id;
Upvotes: 2
Views: 190
Reputation: 381
The models need to be bound in the models themselves, not in the controller.
Upvotes: 1