fix(post): 게시글 첨부파일 조회 오류 수정

문제:
- morphMany 사용 시 "No morph map defined" 에러 발생
- 시스템 게시판 파일 조회 시 tenant_id 불일치로 빈 배열 반환

해결:
- AppServiceProvider: Post 모델을 enforceMorphMap에 등록
- Post::files(): morphMany → hasMany(document_type/document_id 기반)로 변경
- Post::files(): TenantScope 제외하여 시스템 게시판 파일 조회 가능

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-28 01:42:47 +09:00
parent ab77bab510
commit bd8adffb34
2 changed files with 12 additions and 3 deletions

View File

@@ -4,6 +4,7 @@
use App\Models\Commons\File;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
@@ -20,9 +21,15 @@ class Post extends Model
'ip_address', 'is_notice', 'is_secret', 'views', 'status',
];
public function files()
/**
* 게시글 첨부파일 (document_type/document_id 기반)
* - 시스템 게시판의 경우 tenant 무관하게 조회해야 하므로 TenantScope 제외
*/
public function files(): HasMany
{
return $this->morphMany(File::class, 'fileable');
return $this->hasMany(File::class, 'document_id')
->where('document_type', 'post')
->withoutGlobalScope(\App\Models\Scopes\TenantScope::class);
}
public function comments()