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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:29:47+00:00 2026-06-14T08:29:47+00:00

I have 2 tables in a database: User and Profile. In a page i

  • 0

I have 2 tables in a database: User and Profile.
In a page i want to see all user with its profile associated by user_id.
The problem is when i update the records cakephp update only the table user and don’t the profile table.. Now i’m very confused but this is my code to update in the UsersController

$this->User->id = $this->request->data['User']['id'];
                if (!$this->User->exists()) {
                    $this->Session->setFlash('Nessun utente trovato con questa corrispondenza');
                }
                if ($this->User->save($this->request->data)) {
                    $this->Session->setFlash('Modifica avvenute con successo');
                    $this->redirect(array('action'=>'index'));
                } 
                else {
                    debug($this->User->invalidFields());
                    $this->Session->setFlash('Errore di salvataggio dati, prova di nuovo');
                }
                $this->redirect(array('action'=>'index'));

and this is my User model:
class User extends AppModel{

public $name = 'User'; 
        public $hasOne = array(
            'Profile' => array('className'    => 'Profile',
            'conditions' => '',
            'dependant' => true,
            'foreignKey'   => 'user_id',
            'associatedKey'   => 'user_id'
            )
    );

        public $validate = array(
            'username' => array(
                'non_vuoto' => array(
                    'rule'=> 'notEmpty',//non è vuoto metodo che eredito da appmodel
                    'message'=> 'Lo username non può essere vuoto'  
                ),
                'stringa_alfanumerica' => array(
                    'rule'=> 'alphaNumeric',//alpha numerico
                    'message'=> 'Lo username deve essere alfanumerica'  
                )
            ),
            'password' => array(
                'non_vuoto' => array(
                    'rule'=> 'notEmpty',//non è vuoto metodo che eredito da appmodel
                    'message'=> 'La password non può essere vuota'  
                ),
                'min_lunghezza' => array(
                    'rule' => array('minLength',5),
                    'message' => 'La password deve contenere almeno 5 caratteri'
                ),
                'max_lunghezza' => array(
                    'rule' => array('maxLength',15),
                    'message' => 'La password deve contenere al massimo 15 caratteri'
                ),
                'password_uguale' => array(
                    'rule' => 'matchPasswords',
                    'message' => 'Le password inserite non coincidono'
                )
            ),
            'password_confirm' => array(
                'non_vuoto' => array(
                    'rule'=> 'notEmpty',//non è vuoto metodo che eredito da appmodel
                    'message'=> 'La password non può essere vuota'  
                )           
            ),
            'email' => array(
                'email_non_valida' => array(
                    'rule' => 'email',
                    'message' => 'L\'email inserita non è valida'
                ),
                'email_univoca' => array(
                    'rule' => 'isUnique',
                    'message' => 'Questa email inserita è già presente nel database'
                )
            ),
            'activation_key' => array(
                'stringa_alfanumerica' => array(
                    'rule' => 'alphaNumeric',//alpha numerico
                    'message'=> 'La chiave di attivazione non è valida'
                ),
                'lunghezza campo' => array(
                    'rule' => array('between',40,40),
                    'message'=> 'La chiave di attivazione non è valida'
                )           
            ),
            'url' => array(
                'url' => array(
                    'rule' => array('url',true), //invalida i protocolli http e https
                    'allowEmpty' => true, //dico che può essere anche vuoto
                    'message' => 'L\'url inserito non è valido'
                )
            ),
            'description' => array(
                'max_lunghezza' => array(
                    'rule' => array('maxLenght',100),
                    'allowEmpty' => true,
                    'message' => 'La descrizione è troppo lunga'
                )
            )
        );

        //metodo mio dichiarato
        public function matchPasswords($data){
            //Il primo dato non è criptato se è nella variabile data se utilizzavo il this lui vede il campo password e quindi prendo il campo che ho diciharato
            if ($data['password']==$this->data['User']['password_confirm']){
                return true;
            }
            //mando l'errore se non coincidono gli dico invalidami quel campo
            $this->invalidate('password_confirm','Le due password non coincidono');
            return false;
        }

        //metodo automatico non necessario avviene sempre prima del salvataggio in questo caso
        public function beforeSave(){
            //se trova il campo password cripta
            if (isset($this->data['User']['password'])){
                $this->data['User']['password']=AuthComponent::password($this->data['User']['password']);
            }
            return true;
        }

    }
?>

I can’t update my user’s profile why?

i have try to create the model for the Profile like this but nothing

class Profile extends AppModel{
        public $name = 'Profile'; 
        var $belongsTo = array('User' =>
                        array(
                            'foreignKey' => 'user_id'
                        )
                    ); 

    }

Help me please

  • 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-14T08:29:49+00:00Added an answer on June 14, 2026 at 8:29 am

    In the topmost code block you aren’t making any references to the profile, so it is only right, that you don’t update anything.

    At least you have to have something like this:

    loadModel("Profile"); //not necessary
    $this->Profile->find('first', array('conditions' => array('user_id'=>'user_id')));
    $this->Profile->save($data_you_want_to_save);
    

    If this didn’t help, I recommend posting the whole function code like this and clarifying your problem:

    public function update($user_id) {
        *your code should be here so we know what function you are in*
    }
    

    Also you might want to reread the blog tutorial. I pointed you right to a good example of a simple edit function.

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

Sidebar

Related Questions

I have two tables in my database: user and media_contact . The media_contact table
Imagine we have two tables in the database, user (FK id_role) and role (PK
I have a database with three tables: user_table country_table city_table I want to write
I have a database situation where I'd like to get a user profile row
I have two tables in my database which have a one-to-one relationship. I want
I have a database table where the user marks files to be downloaded. Subsequently,
I have a table in my database like this: [id] [uniqueidentifier] NOT NULL, [user_id]
Consider the below situation I have a database table as below user_id user_rank ------------------
I have the fallowing database table 'table_name': +----+---------+--------------+ | ID | user_id | meta_key1
I have a database in which there is a user table & how many

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.