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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:03:59+00:00 2026-05-30T08:03:59+00:00

I have an edit form where I would like to update a number of

  • 0

I have an edit form where I would like to update a number of models. The problem is that my main model, Units, belongsTo Location (since one Location can hasMany Units). The cakephp manual describes how to saveAll when your related model data belongsTo your main model, but not how it works in reverse. The code I use below obviously doesn’t update Location.address.

from edit.ctp:

<?php    
echo $this->Form->create('Unit', array('url'=>array('action' =>'edit'));
echo $this->Form->input('unitnum', array('label' => 'Unit\'s Name/Number'));
echo $this->Form->input('Location.0.address');

echo $this->Form->end('Update Property');?>

And here is my controller code:

function edit($id) {
$this->Unit->id = $id;    
if (empty($this->data)) {        
$this->data = $this->Unit->read();    
} else {        
    if ($this->Unit->saveAll($this->data)) {            
        $this->Session->setFlash('Your property has been updated.');            

        }   
  }
 }

Note: I have also tried to use echo $this->Form->input(‘Location.address’); and while it beautifully pre-populates my field for me, it still doesn’t update the Location address if I change it.

UPDATE
I have discovered that when I submit my form, cake instead of updating the Location address, ADDS a new location with all the new information!

2nd UPDATE
I have also discovered that additionally, while cake will save a NEW record for the RELATED model data (that the main model belongsTo), it doesn’t update the Unit (the main model) info.

  • 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-30T08:04:00+00:00Added an answer on May 30, 2026 at 8:04 am

    You need to pass the location ID or it will think it is a new address.

    Commonly the way this is done is to show the various locations in a dropdown (id/name) that will allow you to select the location you want to add a unit to. If you already know the unit, then you should include the Location.id as a hidden field and then only display the location.address, but not as part of the form.

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

Sidebar

Related Questions

I would like to update a form's textbox in winforms with data that is
I have this function to edit all fields that come from the form and
I have a nested form in which I would like the form fields to
I have a form that allows a user to update their profile information, but
So I have a form that I want the user to use to update
When editing a basic User model in Rails from the edit.html.erb form, I would
i have a table called horse, i would like to create a form to
I'd like to create/update a sub-object within an admin edit dialog. I have a
So I have an input form that I want to use to update a
I have an User model who has_one :preference , but I would like to

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.