【问题标题】:cakephp 1.3 shell not getting associated modelscakephp 1.3 shell 没有得到关联的模型
【发布时间】:2023-03-06 19:00:01
【问题描述】:

我在从 cakephp shell 获取相关模型信息时遇到问题,这是我的 shell:

class ContactShell extends Shell{
    public $uses = array('Contact');

    public function main(){ 
        $contacts = $this->Contact->find('all', array(
                     'conditions' => array(
                   'Contact.is_sent' => false,
                   'Contact.is_bounce' => false),
                 'contain' => array('City' => array(
                           'fields' => array('City.name')))));
        debug($contacts);
    }
 }

当我运行这个 shell 时出现错误

警告:模型“Contact”与 C:\wamp\www\togo 中的模型“City”没有关联 design\cake\libs\model\behaviors\containable.php 在第 363 行

并且结果只包含联系人模型数组。

控制器中的相同脚本显示了 City 数组

关于如何让关联在 cakephp shell 中工作的任何建议???

我也尝试过使用

    $this->Contact->recursive = 1;

【问题讨论】:

    标签: shell cakephp model


    【解决方案1】:

    您是否将 Containable 行为添加到联系模型中?

    public function main(){ 
        $this->Contact->Behaviors->attach('Containable');
        $contacts = $this->Contact->find('all', array(
                     'conditions' => array(
                         'Contact.is_sent' => false,
                         'Contact.is_bounce' => false),
                     'contain' => array('City' => array(
                           'fields' => array('City.name')))));
    }
    

    如果这不起作用,我们需要查看联系人模型的定义

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-12-28
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多