We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Problem with Scaffold

Hi,

I have Scaffold a table and when I try to edit a result, I'm getting this message :

Cannot resolve attribute "Id' in the model

The thing is that I don't have any column named "Id". Here's my model class :

<?php

class User extends \Phalcon\Mvc\Model {

/**
 *
 * @var integer
 */
public $UserID;

/**
 *
 * @var string
 */
public $Email;

/**
 *
 * @var string
 */
public $Firstname;

/**
 *
 * @var string
 */
public $Lastname;

/**
 *
 * @var integer
 */
public $IsBlocked;

/**
 *
 * @var string
 */
public $Password;

/**
 *
 * @var string
 */
public $Type;

/**
 * Initialize method for model.
 */
public function initialize() {

    $this->setSource('User');

    $this->hasMany("UserID", "UserRole", "UserID");   
    $this->hasMany("UserID", "UserModule", "UserID");
}

/**
 * Independent Column Mapping.
 */
public function columnMap() {

    return array(

        'UserID' => 'UserID', 
        'Email' => 'Email', 
        'Firstname' => 'Firstname', 
        'Lastname' => 'Lastname', 
        'IsBlocked' => 'IsBlocked', 
        'Password' => 'Password', 
        'Type' => 'Type'
    );
}

}

Is there something I'm doing wrong here ? The model have been generated before the scaffold.

thank you.

Daniel



31.3k

By the way, I use to Scaffold other table and I don't have this problem.



98.9k

Probably, the scaffold is expecting a primary key but it can find a one. Does your table a primary key?



31.3k

Hi,

Yes !

CREATE TABLE User ( UserID int(11) NOT NULL AUTO_INCREMENT, Email varchar(200) COLLATE utf8_unicode_ci NOT NULL, Firstname varchar(45) COLLATE utf8_unicode_ci NOT NULL, Lastname varchar(45) COLLATE utf8_unicode_ci NOT NULL, IsBlocked tinyint(4) NOT NULL DEFAULT '0', Password text COLLATE utf8_unicode_ci NOT NULL, Type varchar(45) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'System', PRIMARY KEY (UserID), UNIQUE KEY UserID_UNIQUE (UserID) ) ENGINE=InnoDB AUTO_INCREMENT=736 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Table for user informations.';

dlusignan

Change your columnMap to:

public function columnMap() {

return array(

'UserID' => 'id', 'Email' => 'Email', 'Firstname' => 'Firstname', 'Lastname' => 'Lastname', 'IsBlocked' => 'IsBlocked', 'Password' => 'Password', 'Type' => 'Type' ); }