fix(item-master): EntityRelationship::link() 파라미터 순서 및 관계 로드 오류 수정
- EntityRelationship::link() 호출 파라미터 순서 수정 (3개 파일) - ItemSectionService: tenantId를 첫 번째 파라미터로 변경 - ItemBomItemService: tenantId를 첫 번째 파라미터로 변경 - ItemFieldService: tenantId를 첫 번째 파라미터로 변경 - ItemSection 모델의 fields()/bomItems() 관계 메서드 문제 해결 - 쿼리빌더 반환으로 인한 addEagerConstraints() 에러 수정 - loadRelatedEntities() 메서드 신규 추가 - with()/load() 대신 setRelation()으로 데이터 설정 - 영향받은 서비스 파일 전체 수정 - ItemSectionService, SectionTemplateService, ItemMasterService
This commit is contained in:
@@ -25,10 +25,14 @@ public function index(): Collection
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
|
||||
return ItemSection::where('tenant_id', $tenantId)
|
||||
->with(['fields', 'bomItems'])
|
||||
$sections = ItemSection::where('tenant_id', $tenantId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
// entity_relationships 기반이므로 각 섹션별로 관련 엔티티 로드
|
||||
$sections->each(fn ($section) => $section->loadRelatedEntities());
|
||||
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +85,7 @@ public function store(array $data): ItemSection
|
||||
);
|
||||
}
|
||||
|
||||
return $section->load(['fields', 'bomItems']);
|
||||
return $section->loadRelatedEntities();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +112,7 @@ public function update(int $id, array $data): ItemSection
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
return $section->fresh()->load(['fields', 'bomItems']);
|
||||
return $section->fresh()->loadRelatedEntities();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,12 +148,14 @@ public function destroy(int $id): void
|
||||
$section->delete();
|
||||
|
||||
// 4. 하위 필드/BOM도 Soft Delete
|
||||
foreach ($section->fields as $field) {
|
||||
$section->loadRelatedEntities();
|
||||
|
||||
foreach ($section->getRelation('fields') as $field) {
|
||||
$field->update(['deleted_by' => $userId]);
|
||||
$field->delete();
|
||||
}
|
||||
|
||||
foreach ($section->bomItems as $bomItem) {
|
||||
foreach ($section->getRelation('bomItems') as $bomItem) {
|
||||
$bomItem->update(['deleted_by' => $userId]);
|
||||
$bomItem->delete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user