Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6920543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:09:40+00:00 2026-05-27T10:09:40+00:00

I’ve got a CakePHP save method that is saving multiple entries per one save

  • 0

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:

SQL rows

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:09:40+00:00Added an answer on May 27, 2026 at 10:09 am

    Ahhh…figured it out. It was a stylesheet declaration someone had put in the code with an incorrect relative path — it was passing in “css” as the simulation ID, which is why the duplicate was being inserted as 0!

    This was what helped me deduce it (https://stackoverflow.com/a/353493/390977):

    Check your layout for non-existent links, for example a misconfigured
    link to favicon.ico will cause the controller action to be triggered
    for a second time. Make sure favicon.ico points towards the webroot
    rather than the local directory, or else requests will be generated
    for /controller/action/favicon.ico rather than /favicon.ico – and thus
    trigger your action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.