CakePHP var $ useTable = false仍会产生“基表或未查找的视图:1146 ...”错误

时间:2012-07-27 13:10:26

标签: model cakephp-2.0

我无法解决这个问题,我宁愿不用unBinds填充我的控制器。我有一个需要验证的圣人薪酬表。因此,我建立了一个sage模型,其中包含以下内容:

class Sage extends AppModel {

    var $useTable = false;
    var $_schema = array(
        'CardHolderName'        =>array('type'=>'string', 'length'=>100), 
        'CardType'      =>array('type'=>'string', 'length'=>100), 
        'CardNumber'        =>array('type'=>'string', 'length'=>100), 
        'EndMonth'      =>array('type'=>'string', 'length'=>100), 
        'EndYear'       =>array('type'=>'string', 'length'=>100), 
        'BILLING_address_line_1'        =>array('type'=>'string', 'length'=>100), 
        'BILLING_city'      =>array('type'=>'string', 'length'=>100), 
        'BILLING_county'        =>array('type'=>'string', 'length'=>100), 
        'BILLING_country'       =>array('type'=>'string', 'length'=>100), 
        'BILLING_country'       =>array('type'=>'string', 'length'=>100), 
        'BILLING_post_code'     =>array('type'=>'string', 'length'=>100), 
        'DELIVER_name'      =>array('type'=>'string', 'length'=>100), 
        'DELIVER_address_line_1'        =>array('type'=>'string', 'length'=>100), 
        'DELIVER_city'      =>array('type'=>'string', 'length'=>100), 
        'DELIVER_county'        =>array('type'=>'string', 'length'=>100), 
        'DELIVER_country'       =>array('type'=>'string', 'length'=>100), 
        'DELIVER_post_code'     =>array('type'=>'string', 'length'=>100), 
        'CSV'       =>array('type'=>'string', 'length'=>3)

    );

    public $validate = array(
        'CardHolderName'=>array(
            'Please enter your name.'=>array(
                'rule'=>'notEmpty',
                'message'=>'Please enter your name.'
            )
        ),
        'CardType'=>array(
            'Card Type Select'=>array(
                'rule'=>'notEmpty',
                'message'=>'You must select a card type.'
            )
        ),
        'CardNumber'=>array(
            'Card Number Length'=>array(
                'rule'=> array('between', 16, 20),
                'message'=>'Card numbers are at least 16 numbers long.'
            ),
            'Not empty'=>array(
                'rule'=> 'notEmpty',
                'message'=>'Card Number is missing.'
            ),
            'Is a number' => array(
                'rule' => 'numeric',
                'message' => 'This must be a number (no spaces either).'
            )
        ),
        'EndMonth'=>array(
            'End Month Select'=>array(
                'rule'=>'notEmpty',
                'message'=>'No Month.'
            )
        ),
        'EndYear'=>array(
            'End Year Select'=>array(
                'rule'=>'notEmpty',
                'message'=>'No Year.'
            )
        ),
        'CSV'=>array(
            'Card Number Length'=>array(
                'rule'=> array('between', 3, 3),
                'message'=>'A CSV is 3 numbers long.'
            ),
            'CSV not empty'=>array(
                'rule'=>'notEmpty',
                'message'=>'Please enter your security code.'
            ),
            'Is a number' => array(
                'rule' => 'numeric',
                'message' => 'A CSV is 3 numbers long.'
            )
        )
    );
}

但是当我进入订单的索引页面(其中有$this->paginate('Order');)时,我得到以下内容:

  

错误:SQLSTATE [42S02]:找不到基表或视图:1146表   'wr_shop.sages'不存在

     

SQL查询:SELECT COUNT(*)AS count FROM wr_shoporders AS   Order LEFT JOIN wr_shopusers AS User ON(Orderuser_id =   Userid)LEFT JOIN wr_shopbaskets AS Basket ON   (Basketorder_id = Orderid)LEFT JOIN wr_shopsages AS   Sage ON(Sageorder_id = Orderid)WHERE 1 = 1

有人能告诉我我错过了什么,我似乎无法在任何地方找到答案。

--- UPADATE ---我通过创建一个'sages'表来临时修复这个问题,即使它永远不会保存任何数据。

2 个答案:

答案 0 :(得分:0)

您的Sage模型未正确加载,而是使用AppModel实例。

检查路径,文件名和文件扩展名:app / Model / Sage.php

答案 1 :(得分:0)

今天我遇到了同样的问题,在我的情况下问题是我的表单发送了ID字段。当我删除I​​D字段时,验证执行得很好。