I've got a CakePHP save method that is saving multiple entries per one save request. I have no idea why -- my AppModel doesn't have any special functions, nor does my AppController. My Controller and Model are pretty basic. Here's what I have:
BalanceSheet Model
<?php
class BalanceSheet extends AppModel {
var $belongsTo = array(
'Simulation' => array(
'foreignKey' => 'simulation_id',
)
);
}
?>
BalanceSheets Controller
<?php
class BalanceSheetsController extends AppController {
function generate($simulation_id) {
$data = array(
'BalanceSheet' => array(
'simulation_id' => $simulation_id,
'year' => 2004
)
);
$this->BalanceSheet->save($data);
}
}
?>
Database Schema
CREATE TABLE IF NOT EXISTS `balance_sheets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`simulation_id` int(11) NOT NULL,
`year` int(11) NOT NULL,
`buildings_and_improvements` float NOT NULL DEFAULT '0',
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=72 ;
When my balance sheet table is empty, and I navigate to balance_sheets/generate/10, this is the result:
What. What the heck? What's going on there? How can I get it to just save once?
EDIT
Turns out my controller's being called multiple times (I'm not sure why). I'll keep stepping through the debugger to find out what's going on.