From 6db9d119c1e29afcba395583320d26e2e77133f3 Mon Sep 17 00:00:00 2001 From: taekyoungc Date: Thu, 23 Apr 2026 15:43:19 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=9C=EC=A3=BC=20=EC=B5=9C=EC=8B=A0=20?= =?UTF-8?q?=ED=97=A4=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EB=88=84=EB=9D=BD=EC=9D=84=20=EB=B3=B5=EA=B5=AC?= =?UTF-8?q?=ED=95=9C=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /bag/order/create 경로에서 발생한 undefined method(whereLatestHead) 오류를 막기 위해 BagOrderModel에 조회 스코프를 추가한다. Made-with: Cursor --- app/Models/BagOrderModel.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Models/BagOrderModel.php b/app/Models/BagOrderModel.php index f56023e..ead93ca 100644 --- a/app/Models/BagOrderModel.php +++ b/app/Models/BagOrderModel.php @@ -10,9 +10,26 @@ class BagOrderModel extends Model 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', ];