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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:23:05+00:00 2026-05-23T09:23:05+00:00

I have 2 tables liked in CakePHP app, one is Users which hasOne Profile

  • 0

I have 2 tables liked in CakePHP app, one is Users which hasOne Profile liked to.

I have managed to automatically create entries in both when creating a new user, but, when I try to edit everything in my user-edit page, it will create a new profile entry, causing my user to have 2 profiles linked to.

Both models are perfectly coded and linked, as I said, I’m able to create a new user and the system automatically creates the profile and links it.

Here is my user_controller.php with the edit function that is not working properly:

function edit($id = null) {
    if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid User', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->User->save($this->data)) {
                $this->data['Profile']['user_id'] = $this->User->id;
                $this->User->Profile->save($this->data);
                $this->Session->setFlash(__('User saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->User->read(null, $id);
        }
    }

Thanks a lot for the help!

  • 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-23T09:23:06+00:00Added an answer on May 23, 2026 at 9:23 am

    Well, from what it appears by your code it is doing exactly what you’re telling it to do. It is taking the user.id and saving a new profile with it.

    There’s no condition set on $this->User->Profile->save() by the looks of your code. You need to specify what profile to save the edits too. Otherwise Cake is gonna think you want to save a new one. So, if you have the Profile ID in a hidden form field it should look something like this

    $this->User->Profile->save(
        $this->data,
        array(
            'conditions' => array(
                 'Profile.id' => $this->data['Profile']['id']
            )
        )
    );
    

    Now you should be updating a specific profile instead of just saving a new one every time.

    Let me know if it works or not.

    Edit:

    After giving it some thought it is very weird that you’re even able to save two profiles with the same user ID. This should have failed at the database level, before it was even saved. I would recommend setting up a unique index on profiles.user_id as well to ensure you don’t run into problems in the future where a user has multiple profiles.

    (Unless it was intended behavior to have multiple profiles with the same user in which case ignore the edit!)

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

Sidebar

Related Questions

I have built a CakePHP app that creates appointments which have both a client
I have two tables: Users and Profiles. A user may have a profile and
I've one model, which has several(6) linked tables. Most of times, I use this
Using cakephp, I have a generic address table, which I want to link to
I have a CakePHP 1.3 application that has a login system, which works well.
I have two models in cakePHP, one is Parts and the other is Orders
I have the need to create the functionality to allow my registered users to
For Example I have tables - Orders1, Orders2, Orders3, Users. I need to make
I have set up Auth and ACL successfully on my cakePHP app. How, now
I'm doing a blog in CakePHP, so I have two tables in my database

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.