refactor: 모델 개선 및 관계 정의 수정
- Material 모델 - fillable 속성 추가 (모든 필드 명시) - User 모델 - BelongsToMany 관계 타입 힌트 추가 - Product 모델 - fillable에 unit 필드 추가 - casts 순서 정리 (boolean 그룹화) - ProductComponent 모델 - quantity 캐스트 정밀도 변경 (decimal:4 → decimal:6) - referencedItem() 메서드 추가 (동적 관계 로드) - product(), material() 관계 메서드 수정 (where 조건 추가) - is_default 캐스트 제거 (컬럼 없음) - Tenant 모델 - options 캐스트 추가 (array) - scopeActive() 추가 (trial, active 상태 필터링) - isActive(), isTrial() 헬퍼 메서드 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -28,8 +28,7 @@ class ProductComponent extends Model
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'quantity' => 'decimal:4',
|
||||
'is_default' => 'boolean',
|
||||
'quantity' => 'decimal:6',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
'deleted_at' => 'datetime',
|
||||
@@ -39,7 +38,6 @@ class ProductComponent extends Model
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 상위 제품 (모델/제품)
|
||||
*/
|
||||
@@ -49,19 +47,35 @@ public function parentProduct()
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 제품 (ref_type = PRODUCT일 때만 의미 있음)
|
||||
* 참조된 제품 또는 자재를 동적으로 가져오기
|
||||
* ref_type에 따라 Product 또는 Material을 반환
|
||||
*/
|
||||
public function childProduct()
|
||||
public function referencedItem()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'child_product_id');
|
||||
if ($this->ref_type === 'PRODUCT') {
|
||||
return $this->belongsTo(Product::class, 'ref_id');
|
||||
} elseif ($this->ref_type === 'MATERIAL') {
|
||||
return $this->belongsTo(Material::class, 'ref_id');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 자재 (ref_type = MATERIAL일 때만 의미 있음)
|
||||
* 하위 제품 (ref_type = PRODUCT일 때만)
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class, 'ref_id')
|
||||
->where('ref_type', 'PRODUCT');
|
||||
}
|
||||
|
||||
/**
|
||||
* 하위 자재 (ref_type = MATERIAL일 때만)
|
||||
*/
|
||||
public function material()
|
||||
{
|
||||
return $this->belongsTo(Material::class, 'material_id');
|
||||
return $this->belongsTo(Material::class, 'ref_id')
|
||||
->where('ref_type', 'MATERIAL');
|
||||
}
|
||||
|
||||
// ---------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user