gpt4 book ai didi

php - 当我尝试 CakePHP 方式时,Cakephp 2.8.x 查询访问冲突。正常查询有效

转载 作者:行者123 更新时间:2023-11-29 11:19:05 28 4
gpt4 key购买 nike

我创建了一个查询,但现在我需要将其重构为 CakePHP 标准。只是我似乎无法让它工作。

这是我的工作查询:

 $query = $this->Transfer->query( "SELECT DISTINCT emailaddresses.emailaddress
FROM transfers
JOIN emailaddresses
ON (emailaddresses.transfer_id = transfers.transfer_id AND emailaddresses.type <> 'SENDER' AND emailaddresses.received_state = 'DELIVERED')
WHERE transfers.created_user_id = $created_user_id " );

这个查询正在工作,但是当我尝试 Cakeify 时,我的表电子邮件地址的访问被拒绝。这是 CakePHP 查询:

                $query = $this->Transfer->find('all', array(
'fields' => 'DISTINCT Emailaddress.emailaddress ',
'conditions' => array(
'transfers.created_user_id' => $created_user_id
),
'joins' => array(
array(
'table' => 'Emailaddress.emailaddress',
'type' => 'INNER',
'conditions' => array(
'Emailaddress.transfer_id' => 'Transfer.transfer_id',
'Emailaddress.type' => 'SENDER',
'Emailaddress.received_state' => 'DELIVERED'

)
)
)
));

我需要更改什么才能使此查询符合 Cake 标准?

最佳答案

您的查询如下:

$query = $this->Transfer->find('all', array(
//'fields' => 'DISTINCT Emailaddress.emailaddress ',
'fields' => array('DISTINCT Emailaddress.emailaddress '),
'conditions' => array(
//'transfers.created_user_id' => $created_user_id
'Transfer.created_user_id' => $created_user_id
),
'joins' => array(
array(
//'table' => 'Emailaddress.emailaddress',
'table' => 'emailaddresses',
'alias' => 'Emailaddress', // add alias
'type' => 'INNER',
'conditions' => array(
'Emailaddress.transfer_id' => 'Transfer.transfer_id',
//'Emailaddress.type' => 'SENDER',
'Emailaddress.type <>' => 'SENDER',
'Emailaddress.received_state' => 'DELIVERED'

)
)
)
));

了解更多:

关于php - 当我尝试 CakePHP 方式时,Cakephp 2.8.x 查询访问冲突。正常查询有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39250623/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com