entity 연결 수정 및 코드정리

This commit is contained in:
2025-12-29 13:55:43 +09:00
parent 5204000d34
commit 9de32fe394
15 changed files with 321 additions and 978 deletions

View File

@@ -1,5 +1,5 @@
import { BaseModel } from 'src/common/entities/base.entity';
import { FarmModel } from 'src/farm/entities/farm.entity';
import { CowModel } from 'src/cow/entities/cow.entity';
import {
Column,
Entity,
@@ -254,7 +254,10 @@ export class MptModel extends BaseModel {
creatine: number;
// Relations
@ManyToOne(() => FarmModel, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'fk_farm_no' })
farm: FarmModel;
@ManyToOne(() => CowModel, {
onDelete: 'CASCADE',
createForeignKeyConstraints: false
})
@JoinColumn({ name: 'cow_id', referencedColumnName: 'cowId' })
cow: CowModel;
}

View File

@@ -20,7 +20,7 @@ export class MptService {
async findByCowShortNo(cowShortNo: string): Promise<MptModel[]> {
return this.mptRepository.find({
where: { cowShortNo: cowShortNo, delDt: IsNull() },
relations: ['farm'],
relations: ['cow', 'cow.farm'],
order: { testDt: 'DESC' },
});
}
@@ -28,7 +28,7 @@ export class MptService {
async findByCowId(cowId: string): Promise<MptModel[]> {
return this.mptRepository.find({
where: { cowId: cowId, delDt: IsNull() },
relations: ['farm'],
relations: ['cow', 'cow.farm'],
order: { testDt: 'DESC' },
});
}