0

I have this model file:

// Myfan.php
class Myfan extends AppModel {
    var $name = 'Myfan';
    var $useTable = 'myfans';

    function getAll(){
        return $this->find('all');
    }

}

I try this query (which is simplified to isolate the problem) inside my controller class.

$Data=$this->Myfan->find('all',
            array(
                'limit' => 10
        ));

From MySQL I get this error:

SQLSTATE[42S22]:
   Column not found: 1054 Unknown column 'Myfan.name' in 'field list'

My table structure like this:

CREATE TABLE IF NOT EXISTS `myfans` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `screen_name` varchar(50) CHARACTER SET utf8 NOT NULL,
  `age` int(20) DEFAULT NULL,
  `color` int(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=705314 ;

I removed myapp_cake_model_default_mydatabase_myfans file from /httpdocs/app/tmp/cache/models folder. Cake created file automatically but I still get the same error. How can I solve this?

I even don't have "name" field inside my table now. But I'm not sure whether I had before or not. Where does Cake checks for that field?

Edit: I get the same error when I change query to this:

$Data=$this->Myfan->find('all', array(
        'conditions' => array('Myfan.screen_name' => $screenname),
        'order' => array('Myfan.id DESC')
    ));

Also my AppModel

// AppModel.php
App::uses('Model', 'Model');

class AppModel extends Model {
}
4

1 回答 1

1

如果您使用不同的显示字段,您还需要告诉模型:

$this->displayField = 'screen_name';

对于“名称”和“标题”蛋糕能够自动检测。

于 2013-02-09T10:35:02.320 回答