From c27fc01907f9ca849713504cde24609604be7447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9C=A0=EB=B3=91=EC=B2=A0?= Date: Wed, 18 Mar 2026 21:28:48 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20[changes]=20=EC=A0=88=EA=B3=A1=ED=92=88?= =?UTF-8?q?=20resolve-item=20specification=20=EC=BB=AC=EB=9F=BC=20500=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ..._bending_resolve_item_specification_fix.md | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 changes/20260318_bending_resolve_item_specification_fix.md diff --git a/changes/20260318_bending_resolve_item_specification_fix.md b/changes/20260318_bending_resolve_item_specification_fix.md new file mode 100644 index 0000000..0f7b2b1 --- /dev/null +++ b/changes/20260318_bending_resolve_item_specification_fix.md @@ -0,0 +1,70 @@ +# [API] 절곡품 resolve-item 500 에러 수정 (specification 컬럼) + +**날짜:** 2026-03-18 +**작성자:** Claude Code +**대상:** sam-api (PHP Laravel) +**심각도:** High +**영향 범위:** 절곡품 재고생산 등록 > 품목 매핑 조회 + +--- + +## 1. 증상 + +절곡품 재고생산 등록 화면에서 품목명 + 종류 + 모양&길이 3개 드롭다운 선택 시 **500 Internal Server Error** 발생. + +``` +SQLSTATE[42S22]: Column not found: 1054 Unknown column 'specification' in 'field list' +SQL: select `id`, `code`, `name`, `specification`, `unit` from `items` where ... +``` + +--- + +## 2. 원인 + +`BendingCodeService::resolveItem()` 메서드에서 Eloquent eager loading에 `specification`을 DB 컬럼으로 직접 지정하고 있었으나, `items` 테이블에는 `specification` 컬럼이 존재하지 않음. + +`specification`은 **Item 모델의 accessor** (`$appends`)로, `attributes` JSON 컬럼에서 `spec` 또는 `specification` 값을 추출하는 가상 속성. + +```php +// Item 모델 +protected $appends = ['specification']; + +public function getSpecificationAttribute(): ?string +{ + $attrs = $this->attributes['attributes'] ?? null; + // ... + return $attrs['spec'] ?? $attrs['specification'] ?? null; +} +``` + +--- + +## 3. 수정 내용 + +**파일:** `app/Services/BendingCodeService.php:139` + +```php +// 변경 전 (500 에러) +->with('item:id,code,name,specification,unit') + +// 변경 후 (정상) +->with('item:id,code,name,attributes,unit') +``` + +`specification` 대신 실제 DB 컬럼 `attributes`를 select하면, accessor가 자동으로 `specification` 값을 계산하여 반환함. + +--- + +## 4. 검증 + +- 매핑된 조합 선택 시: 200 응답 + `item_code`, `item_name`, `specification`, `expected_code` 정상 반환 +- 매핑 안 된 조합 선택 시: 404 응답 + `expected_code` 정상 반환 (500 에러 해소) + +--- + +## 5. 관련 변경 + +| 항목 | 설명 | +|------|------| +| 동일 커밋 | `expected_code` 필드 추가 (BendingController.php) | +| 프론트엔드 | BendingLotForm.tsx에서 `expected_code` 표시 로직 적용 완료 | \ No newline at end of file