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 8007793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:56:27+00:00 2026-06-04T17:56:27+00:00

I’m new to CakePHP and hope someone could help me with this one. I

  • 0

I’m new to CakePHP and hope someone could help me with this one. I can’t solve it on my own.

I have a table ‘games’, with the following columns:

- id
- date

And a second table ‘reports’, with the following columns:

- id
- report
- game_id (foreign key)

Game hasOne report and report belongsTo game.

I’m trying to build a form that adds a report to an existing game. Whenever I add a new report, it creates a duplicate record. I have read that if Cake doesn’t know the id, this will happen. And when I debug, the id-field is empty.

This is my aim: If there isn’t a report for a game yet, an add-link will appear and if a report exists for a specific game, there’s update link. Or there’s respectively one link to a form that adds or edits report depending on if there is/isn’t one. How this can be done?

I have read that in beforeSave() -function, you could specify when create and when edit a record. I don’t have an idea how this can be done.

Currently my only solution is to validate the form and set game_id isUnique and to inform to the user that there’s already a report with this game_id.

Big thank you to anyone, who could help me with this!

  • 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-06-04T17:56:28+00:00Added an answer on June 4, 2026 at 5:56 pm

    You could just check beforehand.

    if ($this->Report->hasAny(array('game_id' => $this->data['Report']['game_id']))) {
      // update
      $existing = $this->Report->find('first', array(
        'conditions' => array(
          'game_id' => $this->data['Report']['game_id']
        )
      ));
      $this->Report->id = $existing['Report']['id'];
    } else {
      $this->Report->create();
    }
    // save or update
    $this->Report->save($this->data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
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 to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
I have two tables with like below codes: Table: Accounts id | username |

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.