2014-11-04 72 views
0

我是Cake php的新手。 我有使用问题烘烤CakePHP烘烤所有未知问题

我设置了用户表迁移

public $migration = array(
     'up' => array(
      'create_table' => array(
       'users' => array(
        'user_id' => array('type' => 'integer', 'null' => false, 'key' => 'primary'), 
        'username' => array('type' => 'string', 'null' => false, 'length' => 250), 
        'password' => array('type' => 'text', 'null' => false), 
        'created' => array('type' => 'string', 'null' => false, 'length' => 14), 
        'modified' => array('type' => 'string', 'null' => true, 'default' => null, 'length' => 14), 
        'indexes' => array(
         'PRIMARY' => array('column' => 'user_id', 'unique' => 1) 
        ) 
       ) 
      ) 
     ), 
     'down' => array(
      'drop_table' => array(
       'users' 
      ) 
     ) 
    ); 

和迁移的数据库文件,然后我试图做的命令“蛋糕烘烤所有” 的问题是,用户用belongsTo做了一个参考,并且hasMany 是使用烤的默认值?

class User extends AppModel { 

/** 
* Validation rules 
* 
* @var array 
*/ 
    public $validate = array(
     'user_id' => array(
      'numeric' => array(
       'rule' => array('numeric'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 
     'username' => array(
      'notEmpty' => array(
       'rule' => array('notEmpty'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 
     'date_created' => array(
      'notEmpty' => array(
       'rule' => array('notEmpty'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 
    ); 

    //The Associations below have been created with all possible keys, those that are not needed can be removed 

/** 
* belongsTo associations 
* 
* @var array 
*/ 
    public $belongsTo = array(
     'User' => array(
      'className' => 'User', 
      'foreignKey' => 'user_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 

/** 
* hasMany associations 
* 
* @var array 
*/ 
    public $hasMany = array(
     'User' => array(
      'className' => 'User', 
      'foreignKey' => 'user_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ) 
    ); 

} 

有什么我在这里失踪? 我应该离开它并手动修改它,或者有我错过的配置。

回答

1

有三个简单的解决办法,作为最后的答案陈述蛋糕烤全是下面的默认蛋糕公约和事实创建关联,你在表中有user_id的

  1. 要么重新命名数据库字段从user_id改为id并再次运行该shell。

  2. 运行cake bake并手动选择模型和外壳帮手

  3. 手动删除模型的关联,并在控制器和视图中的引用手动配置数据库的关联。
1

这是正确的。

当您使用cake bake all时,它会按照惯例自动添加对表的引用。当你的表格提到自己时,他确定了'hasMany'和'belongsTo'关系。您应该删除不存在的链接或更改默认生成的链接。参考:baking custom projects