2014-03-06 33 views
0

雖然我嘗試烤一個名爲DeploymentRequest模型,我得到以下錯誤:蛋糕烘烤 - 爲模型GroupsUser表groups_users在數據源未找到

Table groups_users for model GroupsUser was not found in datasource

如果我看着自己的數據庫結構,在沒有任何一點與該連接表有關係(也不需要存在)。儘管如此,我確實有模型組和用戶充當ACL請求者。

錯誤:

Baking test fixture for DeploymentRequest... 

Creating file C:\wamp\apscmdb\app\Test\Fixture\DeploymentRequestFixture.php 
Wrote `C:\wamp\apscmdb\app\Test\Fixture\DeploymentRequestFixture.php` 
Bake is detecting possible fixtures... 
Error: Table groups_users for model GroupsUser was not found in datasource defau 
lt. 
#0 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Model\Model.php(3498): Model->se 
tSource('groups_users') 
#1 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Model\Model.php(1355): Model->ge 
tDataSource() 
#2 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Model\Model.php(864): Model->sch 
ema() 
#3 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Model\Model.php(892): Model->__i 
sset('GroupsUser') 
#4 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\TestTask.ph 
p(405): Model->__get('GroupsUser') 
#5 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\TestTask.ph 
p(396): TestTask->_processModel(Object(Group)) 
#6 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\TestTask.ph 
p(396): TestTask->_processModel(Object(User)) 
#7 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\TestTask.ph 
p(376): TestTask->_processModel(Object(DeploymentRequest)) 
#8 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\TestTask.ph 
p(146): TestTask->generateFixtureList(Object(DeploymentRequest)) 
#9 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\ModelTask.p 
hp(854): TestTask->bake('Model', 'DeploymentReque...') 
#10 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Command\Task\ModelTask. 
php(109): ModelTask->bakeTest('DeploymentReque...') 
#11 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Shell.php(431): ModelTa 
sk->execute() 
#12 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\Shell.php(428): Shell-> 
runCommand('execute', Array) 
#13 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\ShellDispatcher.php(207 
): Shell->runCommand('model', Array) 
#14 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\lib\Cake\Console\ShellDispatcher.php(66) 
: ShellDispatcher->dispatch() 
#15 C:\wamp\cakephp-2.4.5\cakephp-2.4.5\app\Console\cake.php(36): ShellDispatche 
r::run(Array) 
#16 {main} 

數據庫結構:

CREATE TABLE deployment_requests(
    id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
    user_id INT(10) UNSIGNED NOT NULL, 
    environment_id INT(10) UNSIGNED NOT NULL, 
    revision INT(10) UNSIGNED NOT NULL, 
    is_scheduled TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, 
    requested_deploy_date DATE DEFAULT NULL, 
    requested_deploy_time TIME DEFAULT NULL, 
    additional_instructions TEXT DEFAULT NULL, 
    is_completed TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, 
    created DATETIME DEFAULT NULL, 
    modified DATETIME DEFAULT NULL, 
    created_by INT(10) UNSIGNED DEFAULT NULL, 
    modified_by INT(10) UNSIGNED DEFAULT NULL, 
    PRIMARY KEY (id) 
) 
ENGINE = INNODB 
AUTO_INCREMENT = 1 
CHARACTER SET utf8 
COLLATE utf8_unicode_ci; 

CREATE TABLE groups(
    id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
    name_eng VARCHAR(255) NOT NULL, 
    name_fra VARCHAR(255) NOT NULL, 
    description_eng TEXT NOT NULL, 
    description_fra TEXT NOT NULL, 
    created DATETIME DEFAULT NULL, 
    modified DATETIME DEFAULT NULL, 
    created_by INT(10) UNSIGNED DEFAULT NULL, 
    modified_by INT(10) UNSIGNED DEFAULT NULL, 
    PRIMARY KEY (id) 
) 
ENGINE = INNODB 
AUTO_INCREMENT = 4 
AVG_ROW_LENGTH = 5461 
CHARACTER SET utf8 
COLLATE utf8_unicode_ci; 

CREATE TABLE users(
    id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 
    group_id INT(10) UNSIGNED DEFAULT NULL, 
    legal_given_names VARCHAR(255) NOT NULL, 
    legal_family_name VARCHAR(255) NOT NULL, 
    email VARCHAR(255) NOT NULL, 
    username VARCHAR(255) NOT NULL, 
    PRIMARY KEY (id) 
) 
ENGINE = INNODB 
AUTO_INCREMENT = 601943 
AVG_ROW_LENGTH = 3276 
CHARACTER SET utf8 
COLLATE utf8_unicode_ci; 

編輯#1

用戶模型:

<?php 
App::uses('AppModel', 'Model'); 
/** 
* User Model 
* 
* @property Group $Group 
* @property AssetDeploymentUser $AssetDeploymentUser 
* @property AssetGroupDeploymentUser $AssetGroupDeploymentUser 
* @property DeploymentRequest $DeploymentRequest 
* @property DeploymentSupportRequest $DeploymentSupportRequest 
*/ 
class User extends AppModel { 
    public $displayField = 'name'; 
    public $virtualFields = array(
      'name' => 'CONCAT(User.legal_given_names, " ", User.legal_family_name)' 
    ); 

    public $actsAs = array('Acl' => array('type' => 'requester')); 

    public function parentNode() { 
     if (!$this->id && empty($this->data)) { 
      return null; 
     } 
     if (isset($this->data['User']['group_id'])) { 
      $groupId = $this->data['User']['group_id']; 
     } else { 
      $groupId = $this->field('group_id'); 
     } 
     if (!$groupId) { 
      return null; 
     } else { 
      return array('Group' => array('id' => $groupId)); 
     } 
    } 

/** 
* Validation rules 
* 
* @var array 
*/ 
    public $validate = array(
     'legal_given_names' => 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 
      ), 
     ), 
     'legal_family_name' => 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 
      ), 
     ), 
     'email' => array(
      'email' => array(
       'rule' => array('email'), 
       //'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 
      ), 
     ), 
    ); 

    //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(
     'Group' => array(
      'className' => 'Group', 
      'foreignKey' => 'group_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 

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

} 

組模型:

<?php 
App::uses('AppModel', 'Model'); 
/** 
* Group Model 
* 
* @property User $User 
* @property Asset $Asset 
*/ 
class Group extends AppModel { 
    public $displayField = 'name_eng'; 

    public $actsAs = array('Acl' => array('type' => 'requester')); 

    public function parentNode() { 
     return null; 
    } 


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


/** 
* hasAndBelongsToMany associations 
* 
* @var array 
*/ 
    public $hasAndBelongsToMany = array(
    'User' => array(
      'className' => 'User', 
      'joinTable' => 'groups_users', 
      'foreignKey' => 'group_id', 
      'associationForeignKey' => 'user_id', 
      'unique' => 'keepExisting', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'finderQuery' => '', 
     ), 
     'Asset' => array(
      'className' => 'Asset', 
      'joinTable' => 'assets_groups', 
      'foreignKey' => 'group_id', 
      'associationForeignKey' => 'asset_id', 
      'unique' => 'keepExisting', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'finderQuery' => '', 
     ) 
    ); 

} 
+0

您是否擁有GroupsUser模型?如果是,則添加以下內容: 'public $ useTable = false;' – jimmymadon

+0

@jimmymadon該模型在我的代碼中不存在。我也沒有一個表,它會讓字段user_id和group_id創建這樣的關係。 – TekiusFanatikus

+0

你可以粘貼用戶和組模型代碼(主要是$ actsAs和$ hasMany,$ belongsTo等關係屬性)嗎? – jimmymadon

回答

1

根據您的數據庫,我相信Group擁有許多用戶和用戶belongsTo Group。因此,從$ hasAndBelongsToMany屬性中刪除用戶陣列,並在Group.php中添加以下內容:

public $hasMany = = array(
    'User' => array(
      'className' => 'User', 
      'foreignKey' => 'group_id' 
    ) 
); 
+0

我開始意識到有些模型只是需要反彈。當我重新啓動Group模型時,它會烘烤得像它應該有的那樣,沒有habtm屬性。我曾以爲這些東西是由同事烘烤過的,或者是最新的。我不得不重新引用其他3個模型,這些模型給了我這樣的問題。謝謝您的幫助! – TekiusFanatikus

+0

我認爲Group/User模型是用不同的數據庫烘焙的,而不是你在問題中給出的。是要告訴你檢查你的資產和其他模型的關係或重新烘烤模型完全。 – jimmymadon

相關問題