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

  • SEARCH
  • Home
  • 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 3390932
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:44:53+00:00 2026-05-18T03:44:53+00:00

Totally new to Cake. I have this table named Content and another one named

  • 0

Totally new to Cake.

I have this table named Content and another one named ContentMeta (related via content_id). Each entry in Content has a corresponding ContentMeta.

When I add new content, this is the code I’m using to add a new entry to ContentMeta:

if( !empty( $this->data ) ) {

 // Save Content
 $this->Content->create();
 $content = $this->Content->save( $this->data );
 // Save Meta
 if( !empty( $content ) ) {
  $this->data['ContentMeta']['content_id'] = $this->Content->id;
  $this->Content->ContentMeta->save( $this->data );
  $this->Session->setFlash( 'Content has been saved.' );
  $this->redirect( array( 'action' => 'edit', $this->Content->id ) );
 }
}

This works fine and add one new entry to Content and one to ContentMeta.

When it comes to updating the data (edit mode), I’m running into a slight problem. The entry for Content is getting updated without a hitch, but in the ContentMeta table, a new entry is being created upon every single update.

Here’s the code for updating:

$this->Content->id = $id;
// Update Content
$content = $this->Content->save( $this->data );
// Update Meta
if( !empty( $content ) ) {
    //Debugger::dump(print_r($this->data,true));
    $this->data['ContentMeta']['content_id'] = $this->Content->id;
    $this->Content->ContentMeta->save( $this->data );
    $this->Session->setFlash( 'Content has been updated.' );
    $this->redirect( array( 'action' => 'edit', $this->Content->id ) );
}

I’m sure it’s some logical error in this block that is causing this to happen. Can anyone give me an idea where I am going wrong?

Thanks,
m^e

  • 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-18T03:44:53+00:00Added an answer on May 18, 2026 at 3:44 am

    For me it’s missing $this->data[‘ContentMeta’][‘id’] in your data array. And because this field is empty the cake attempt to create a new row.

    So in your form add a hidden id field for the ContentMeta.

    Another thing which I think will improve your code is to use

    $this->Content->saveAll($this->data);
    

    this way you will save your data at once instead of 2 save() calls for each model. Check the manual in the cookboook (and search for saveAll in the text).

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

Sidebar

Related Questions

Totally new to programming so kindly excuse the silly question. I have this URL
I am totally new to C#. I have one service method //actual method public
Totally new to python, and i want to do the following: I have this
I am totally new to Netty and Java, but this afternoon I have managed
Totally new to Capistrano. I have a local git repository that I want to
I'm totally new to this WCF Services thing so any guidelines would be greatly
I'm totally new to AWS. I managed to have an instance that runs PHPMyAdmin.
Totally new to Drupal so be gentle please! Let's say I have a number
Hi I'm totally new to Prestashop and installing it first time can any one
This is a totally new area for me so please be patient. I want

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.