Want to save data field from form into two columns of two models.
        Posted  
        
            by vette982
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by vette982
        
        
        
        Published on 2010-06-15T02:02:36Z
        Indexed on 
            2010/06/15
            2:12 UTC
        
        
        Read the original article
        Hit count: 239
        
I have a Profile model with a hasOne relationship to a Detail model. I have a registration form that saves data into both model's tables, but I want the username field from the profile model to be copied over to the
usernamefield in the details model so that each has the same username.
function new_account()
{
    if(!empty($this->data))
    {
        $this->Profile->modified = date("Y-m-d H:i:s");                 
        if($this->Profile->save($this->data))
        {
            $this->data['Detail']['profile_id'] = $this->Profile->id;
            $this->data['Detail']['username'] = $this->Profile->username;
        $this->Profile->Detail->save($this->data);
        $this->Session->setFlash('Your registration was successful.');
                    $this->redirect(array('action'=>'index'));
        }
    }
}
This code in my Profile controller gives me the error:
Undefined property: Profile::$username
Any ideas?
© Stack Overflow or respective owner