CakePHP Containable:模型“Comp”不与模型“Comp”相关联。

发布于 2024-10-13 02:25:39 字数 907 浏览 2 评论 0原文

我正在尝试使用 Containable 行为进行相当简单的 CakePHP 查找:

$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id),
    'contain' => array(
        'Comp.id' => array(
            'fields' => array('Comp.id'),
        ),
        'Slot' => array(
            'fields' => array(
                'Slot.start_time',
                'Slot.end_time'
            )
        ),
        'Team'
    )
));

...但在执行时会显示警告:

警告 (512):模型“Comp”不是 与型号“Comp”相关 [CORE/cake/libs/model/behaviors/containable.php, 第363行]

我的 Comp 模型的开头如下:

var $name = 'Comp';
var $hasMany = array('Team', 'Round', 'Match');
var $belongsTo = array('Generation');
var $hasAndBelongsToMany = array('Slot');
var $actsAs = array('Containable');

我正在使用 CakePHP 1.3.6

有什么想法可能导致此情况吗?

I am trying to do a fairly simple CakePHP find using the Containable behavior:

$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id),
    'contain' => array(
        'Comp.id' => array(
            'fields' => array('Comp.id'),
        ),
        'Slot' => array(
            'fields' => array(
                'Slot.start_time',
                'Slot.end_time'
            )
        ),
        'Team'
    )
));

...but upon execution a warning is shown:

Warning (512): Model "Comp" is not
associated with model "Comp"
[CORE/cake/libs/model/behaviors/containable.php,
line 363]

The start of my Comp model is as follows:

var $name = 'Comp';
var $hasMany = array('Team', 'Round', 'Match');
var $belongsTo = array('Generation');
var $hasAndBelongsToMany = array('Slot');
var $actsAs = array('Containable');

I am using CakePHP 1.3.6

Any ideas what may be causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-10-20 02:25:39
$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id),
    'fields'     => array('Comp.id'),
    'contain'    => array(
        'Slot'       => array(
            'fields'     => array(
                'Slot.start_time',
                'Slot.end_time'
            )
        ),
        'Team'
    )
));

您告诉它包含相关的Comp.id,这意味着模型CompComp相关,这并不不存在。您可能只想简单地设置 Comp 模型本身的 fields 选项?

$comp = $this->Comp->find('first', array(
    'conditions' => array('Comp.id' => $id),
    'fields'     => array('Comp.id'),
    'contain'    => array(
        'Slot'       => array(
            'fields'     => array(
                'Slot.start_time',
                'Slot.end_time'
            )
        ),
        'Team'
    )
));

You told it to contain the related Comp.id, which means the model Comp related to Comp, which doesn't exist. You probably meant to simply set the fields option of the Comp model itself?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文