CakePHP,注入“LEFT JOIN” (提及关联模型中的字段)到我的更新尝试中

发布于 2024-09-10 08:17:58 字数 1056 浏览 4 评论 0原文

这让我发疯,我试图做类似的事情:

$this->data = $this->Prox->read('proxy',$currentgetdata); 
                    $this->data['Prox']['checked'] = 2;
                    $this->Prox->save();

我有一个模型关联:

class Prox extends AppModel {
    var $name = 'Prox';
    var $primaryKey = 'id';
    ######## Define Model Associations #########
    var $belongsTo = array('Proxylink' => array('className' => 'Proxylink'));
}

但我收到一个错误:

SELECT `Prox`.`proxy` FROM `proxes` AS `Prox` LEFT JOIN `proxylinks` AS `Proxylink` ON (`Prox`.`proxylink_id` = `Proxylink`.`id`) WHERE `Prox`.`id` = '58.22.101.239:808' LIMIT 1

1054: Unknown column 'Prox.proxylink_id' in 'on clause'

我不明白为什么它把它放入查询“LEFT JOIN proxylinks AS Proxylink ON(Proxproxylink_id = Proxylinkid)”我一直无法找到任何关于为什么这样做的文档,就好像它必须尝试在每个查询中包含我的关联模型和当前模型中不存在的字段混合体,我觉得这非常奇怪。任何有关我可以采取哪些措施来使我的保存/更新查询正常工作的建议都将受到赞赏。

This is driving me crazy, I am trying to do something like:

$this->data = $this->Prox->read('proxy',$currentgetdata); 
                    $this->data['Prox']['checked'] = 2;
                    $this->Prox->save();

where I have a model association of:

class Prox extends AppModel {
    var $name = 'Prox';
    var $primaryKey = 'id';
    ######## Define Model Associations #########
    var $belongsTo = array('Proxylink' => array('className' => 'Proxylink'));
}

But I get an error of:

SELECT `Prox`.`proxy` FROM `proxes` AS `Prox` LEFT JOIN `proxylinks` AS `Proxylink` ON (`Prox`.`proxylink_id` = `Proxylink`.`id`) WHERE `Prox`.`id` = '58.22.101.239:808' LIMIT 1

1054: Unknown column 'Prox.proxylink_id' in 'on clause'

I don't get why its putting this into the query "LEFT JOIN proxylinks AS Proxylink ON (Prox.proxylink_id = Proxylink.id)" and I have been unable to find any documentation on why its doing this, its as if it HAS to try to include a non-existant hybrid of a field from my associated model and my current model on each query, which I find extremely bizarre.. any advice is appreciated on what I can do to get my save / update queries to work.

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

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

发布评论

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

评论(1

心的位置 2024-09-17 08:17:58

如果您有 belongsTo 关联,您的“prox”表必须有“proxylink_id”字段。

如果您不想加入关联模型,则必须设置“recursive”选项到-1

If you have belongsTo association your 'prox' table must have 'proxylink_id' field.

If you don't want associative models to be joined you must set 'recursive' option to -1.

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