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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:08:46+00:00 2026-06-04T02:08:46+00:00

I have 2 models I need to save to. In this instance, I do

  • 0

I have 2 models I need to save to. In this instance, I do not need cakePHP to saveAll(), but want to save the content manually.

In my view I have the formHelper setup as “Model2.fieldname” and on post, if I do a pr(), there is an associative array created with [Model2] with the fields.

my code in the controller:

 if($this->request->is("post") {
      if($this->Model1->save($this->request->data) {
           if($this->Model1->Model2->save($this->request->data) {
                $this->Session->setFlash("Success");
           }
      }
 }

It goes ahead and stores the data for model1, but fails on model2. It creates an empty record in the table because there is a created and modified table field, but the rest of the fields are blank. It also fails the validation for model2 (so it does not do any validation.)

Model1 hasOne Model2

I havent done this before so I am convinced I am doing something wrong, so if anyone can help thanks in advance 🙂

  • 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-04T02:08:49+00:00Added an answer on June 4, 2026 at 2:08 am

    You can use cakephp’s saveAssociated() method:

    $this->Model1->saveAssociated($this->request->data);
    

    Read about saveAssociated()

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

Sidebar

Related Questions

I have an arraylist namelist in my model and in my view I need
I have a parent-child view model object structure set up and need to update
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =
I need to upload images using symfony, but ive not been able to do
Let's say I have model app1.models.ModelOne defined with save decorated with @commit_on_success . All
I have two models in Django linked together by ManyToMany relation like this: class
I have a view that displays a list of models. Some of the properties
I have multiple models like this: class Model1(models.Model): user = models.ForeignKey(User) model1_filed1 = models.CharField()
I have two different models that need saving; a TextFile object and a static
I thought I had this one sorted but I have run into a snag.

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.