আমার কাছে নিম্নলিখিত মডেলগুলি রয়েছে:
User
, Customer
,Comment
ব্যবহারকারী Customer
একটিতে মন্তব্য করতে পারে, ব্যবহারকারী অন্য ব্যবহারকারীর মন্তব্যে জবাব দিতে পারে, পুনরাবৃত্তিমূলকভাবে সীমাহীন।
আমি এটি করেছি তবে এটি কেবলমাত্র একটি জবাবের মধ্যে সীমাবদ্ধ এবং আমি সমস্ত উত্তর পেতে চাই:
public async getCommentsForCustomerId(customerId: string): Promise<CustomerComment[]> {
return this.find({where: {customer: {id: customerId}, parentComment: null}, relations: ['childComments']});
}
তবে আমি যে প্রতিক্রিয়া পাচ্ছি তা কেবলমাত্র এক স্তরে নেস্ট করা হয়েছে:
[
{
"id": "7b5b654a-efb0-4afa-82ee-c00c38725072",
"content": "test",
"created_at": "2019-12-03T15:14:48.000Z",
"updated_at": "2019-12-03T15:14:49.000Z",
"childComments": [
{
"id": "7b5b654a-efb0-4afa-82ee-c00c38725073",
"content": "test reply",
"created_at": "2019-12-03T15:14:48.000Z",
"updated_at": "2019-12-03T15:14:49.000Z",
"parentCommentId": "7b5b654a-efb0-4afa-82ee-c00c38725072"
}
]
}
]
আমি কীভাবে এই সমস্তগুলিকে টাইপরমে বাসাতে পারি?
সত্তা সংজ্ঞা (নোট গ্রাহকের নাম পরিবর্তিত হয়েছে নেতৃত্ব) :
@Entity('leads_comments')
export class LeadComment {
@PrimaryGeneratedColumn('uuid')
id: string;
@ManyToOne(type => LeadComment, comment => comment.childComments, {nullable: true})
parentComment: LeadComment;
@OneToMany(type => LeadComment, comment => comment.parentComment)
@JoinColumn({name: 'parentCommentId'})
childComments: LeadComment[];
@RelationId((comment: LeadComment) => comment.parentComment)
parentCommentId: string;
@ManyToOne(type => User, {cascade: true})
user: User | string;
@RelationId((comment: LeadComment) => comment.user, )
userId: string;
@ManyToOne(type => Lead, lead => lead.comments, {cascade: true})
lead: Lead | string;
@RelationId((comment: LeadComment) => comment.lead)
leadId: string;
@Column('varchar')
content: string;
@CreateDateColumn()
created_at: Date;
@UpdateDateColumn()
updated_at: Date;
}