CakePHP,注入“LEFT JOIN” (提及关联模型中的字段)到我的更新尝试中
这让我发疯,我试图做类似的事情:
$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(Prox
。proxylink_id
= Proxylink
。id
)”我一直无法找到任何关于为什么这样做的文档,就好像它必须尝试在每个查询中包含我的关联模型和当前模型中不存在的字段混合体,我觉得这非常奇怪。任何有关我可以采取哪些措施来使我的保存/更新查询正常工作的建议都将受到赞赏。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有 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
.