gpt4 book ai didi

sql - Cakephp find 返回 null

转载 作者:行者123 更新时间:2023-12-03 04:09:49 25 4
gpt4 key购买 nike

大家好,我正在尝试通过发现做两件事,型号争议属于发票。

查找所有发票

invoice.receiver_id=account.id

dispute.invoice_id=发票.id

当前,当我调试时,数组返回 null。 find 语句中应该有 2 个结果

这是我的争议 Controller 中的代码

public function index_admin(){


$id = $this->Auth->User('account_id');

$receiver = $this->Invoice->find('all',array(
'conditions'=>array("AND"=>array(
'Invoice.id'=>'Dispute.invoice_id',
'receiver_id'=>$id))));

$this->set('id',$id);
$this->set('receiver', $receiver);
}

这是在争议 Controller 中,因为我想打印有关有争议的发票的列表。

Query   Error   Affected    Num. rows   Took (ms)
1 SELECT `Invoice`.`id`, `Invoice`.`scheduled`, `Invoice`.`paid`, `Invoice`.`sender_id`, `Invoice`.`receiver_id`, `Invoice`.`template_id`, `Invoice`.`created`, `Invoice`.`expiry_date`, `Invoice`.`total_amount`, `ReceiverAccount`.`id`, `ReceiverAccount`.`street`, `ReceiverAccount`.`city`, `ReceiverAccount`.`postcode`, `ReceiverAccount`.`state`, `ReceiverAccount`.`country`, `ReceiverAccount`.`active`, `ReceiverAccount`.`account_name`, `ReceiverAccount`.`abn`, `SenderAccount`.`id`, `SenderAccount`.`street`, `SenderAccount`.`city`, `SenderAccount`.`postcode`, `SenderAccount`.`state`, `SenderAccount`.`country`, `SenderAccount`.`active`, `SenderAccount`.`account_name`, `SenderAccount`.`abn`, `Template`.`id`, `Template`.`name`, `Template`.`description`, `Template`.`account_id`, `Template`.`active` FROM `pra`.`invoices` AS `Invoice` LEFT JOIN `pra`.`accounts` AS `ReceiverAccount` ON (`Invoice`.`receiver_id` = `ReceiverAccount`.`id`) LEFT JOIN `pra`.`accounts` AS `SenderAccount` ON (`Invoice`.`sender_id` = `SenderAccount`.`id`) LEFT JOIN `pra`.`templates` AS `Template` ON (`Invoice`.`template_id` = `Template`.`id`) WHERE `Invoice`.`id` = 'Dispute.invoice_id' AND `Invoice`.`receiver_id` = 2

编辑---------------------

invoices tables has - id, sender_id, receiver_id, amount, expiry_date, created, paid
disputes table has - id, dispute_date, comment, active

争议模型如下所示

public $belongsTo = array(
'Invoice' => array(
'className' => 'Invoice',
'foreignKey' => 'invoice_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);

public $hasOne = array(
'Sender' => array(
'className' => 'Account',
'foreignKey' =>'sender_id',
'associationForeignKey' => 'accounts_id',),
'Receiver'=> array(
'className' => 'Account',
'foreignKey' =>'receiver_id',
'associationForeignKey' => 'accounts_id',
)
);

争议有一名发送者和一名接收者,因为一张发票只能有一项争议。

最佳答案

如果您喜欢 DisputeController,请尝试以下代码:不知道表名是不是invoices

 $id = $this->Auth->User('account_id');

$options['joins'] = array(
array(
'table' => 'invoices',
'alias' => 'i',
'type' => 'INNER',
'conditions' => array(
'i.id' => 'invoice_id',
'i.receiver_id' => $id
)
));

$receiver = $this->Dispute->find('all', $options);

$this->set('id',$id);
$this->set('receiver', $receiver);

关于sql - Cakephp find 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12489238/

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