/bag/order/create 경로에서 발생한 undefined method(whereLatestHead) 오류를 막기 위해 BagOrderModel에 조회 스코프를 추가한다. Made-with: Cursor
37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
class BagOrderModel extends Model
|
|
{
|
|
protected $table = 'bag_order';
|
|
protected $primaryKey = 'bo_idx';
|
|
protected $returnType = 'object';
|
|
protected $useTimestamps = false;
|
|
|
|
/**
|
|
* 동일 발주 UUID에 대해 bo_version이 최대인 행만 (수정으로 생긴 이전 버전 행은 목록·이력에서 제외).
|
|
* DB에는 버전별 행이 그대로 남고, 조회 시에만 필터한다.
|
|
*/
|
|
public function whereLatestHead(int $lgIdx): self
|
|
{
|
|
$lg = (int) $lgIdx;
|
|
|
|
return $this->where(
|
|
"(bo_uuid, bo_version) IN (SELECT bo_uuid, MAX(bo_version) FROM {$this->table} WHERE bo_lg_idx = {$lg} GROUP BY bo_uuid)",
|
|
null,
|
|
false
|
|
);
|
|
}
|
|
|
|
protected $allowedFields = [
|
|
'bo_uuid', 'bo_version', 'bo_lg_idx', 'bo_gugun_code', 'bo_dong_code',
|
|
'bo_company_idx', 'bo_agency_idx', 'bo_fee_rate', 'bo_order_date',
|
|
'bo_bag_types', 'bo_unit_prices', 'bo_qty_boxes',
|
|
'bo_lot_no', 'bo_hash', 'bo_status', 'bo_orderer_idx',
|
|
'bo_regdate', 'bo_moddate',
|
|
];
|
|
}
|