Files
sam-api/LOGICAL_RELATIONSHIPS_SIMPLE.md
hskwon 1a796462e4 feat: ERD 자동 생성 시스템 구축 및 모델 오류 수정
- GraphViz 설치를 통한 ERD 다이어그램 생성 지원
- BelongsToTenantTrait → BelongsToTenant 트레잇명 수정
- Estimate, EstimateItem 모델의 인터페이스 참조 오류 해결
- 60개 모델의 완전한 관계도 생성 (graph.png, 4.1MB)
- beyondcode/laravel-er-diagram-generator 패키지 활용

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 22:30:28 +09:00

3.5 KiB

논리적 데이터베이스 관계 문서 (간소화)

생성일: 2025-09-24 22:15:54 소스: 알려진 비즈니스 관계 기반 참고: FK 제거 후 논리적 관계 명세

📊 테이블별 논리적 관계

📋 users - 사용자 계정

  • user_tenants (hasMany): user_tenants.user_id → users.id
  • user_roles (hasMany): user_roles.user_id → users.id
  • audit_logs (hasMany): audit_logs.actor_id → users.id (생성자)

📋 tenants - 테넌트 (회사/조직)

  • user_tenants (hasMany): user_tenants.tenant_id → tenants.id
  • classifications (hasMany): classifications.tenant_id → tenants.id (논리적)
  • departments (hasMany): departments.tenant_id → tenants.id
  • products (hasMany): products.tenant_id → tenants.id
  • orders (hasMany): orders.tenant_id → tenants.id

📋 categories - 제품 카테고리 (계층구조)

  • parent (belongsTo): categories.parent_id → categories.id
  • children (hasMany): categories.parent_id → categories.id
  • products (hasMany): products.category_id → categories.id
  • estimates (hasMany): estimates.model_set_id → categories.id (논리적)

📋 products - 제품 마스터

  • category (belongsTo): products.category_id → categories.id
  • tenant (belongsTo): products.tenant_id → tenants.id
  • product_components (hasMany): product_components.parent_product_id → products.id (논리적)
  • order_items (hasMany): order_items.product_id → products.id

📋 departments - 부서 관리 (계층구조)

  • parent (belongsTo): departments.parent_id → departments.id (논리적)
  • children (hasMany): departments.parent_id → departments.id (논리적)
  • tenant (belongsTo): departments.tenant_id → tenants.id

📋 estimates - 견적서 (스냅샷 데이터)

  • category (belongsTo): estimates.model_set_id → categories.id (논리적)
  • tenant (belongsTo): estimates.tenant_id → tenants.id
  • estimate_items (hasMany): estimate_items.estimate_id → estimates.id (논리적)

📋 estimate_items - 견적 아이템

  • estimate (belongsTo): estimate_items.estimate_id → estimates.id (논리적)
  • tenant (belongsTo): estimate_items.tenant_id → tenants.id

📋 product_components - BOM 구성요소 (통합 참조구조)

  • parent_product (belongsTo): product_components.parent_product_id → products.id (논리적)
  • material_or_product (polymorphic): product_components.ref_id → materials.id OR products.id (ref_type 기반)
  • tenant (belongsTo): product_components.tenant_id → tenants.id

📋 classifications - 분류 코드

  • tenant (belongsTo): classifications.tenant_id → tenants.id (논리적)

🚨 중요 사항

논리적 관계 (FK 제거됨)

  • classifications.tenant_id → tenants.id
  • departments.parent_id → departments.id
  • estimates.model_set_id → categories.id
  • estimate_items.estimate_id → estimates.id
  • product_components 모든 관계 (통합 구조)

물리적 FK 유지됨

  • 모든 tenant_id 관계 (멀티테넌트 보안)
  • 권한 관리 시스템 FK
  • 기타 중요 비즈니스 FK

📝 개발 가이드

  1. Service 레이어에서 논리적 무결성 검증 필수
  2. Eloquent 관계 메서드 적극 활용
  3. Soft Delete로 데이터 보호
  4. BelongsToTenant 트레잇으로 테넌트 격리

이 문서는 개발 참조용입니다. 모델 변경 시 업데이트 해주세요.