Population
Comments of a post of a user
Imagine the following scenario:
interface Post {
id: number;
userId: number;
title: string;
body: string;
}
interface Comment {
id: number;
postId: number;
userId: number;
body: number;
}
interface User {
id: number;
name: string;
}import { Post, Comment, User } from './interfaces';
@CrudCollection({ name: 'posts' })
@Injectable()
export class PostsState extends CrudCollectionState<Post, Post['id']> { }
@CrudCollection({ name: 'comments' })
@Injectable()
export class CommentsState extends CrudCollectionState<Comment, Comment['id']> { }
@CrudCollection({ name: 'users' })
@Injectable()
export class UsersState extends CrudCollectionState<User, User['id']> { }
@CrudEntities({
name: 'users',
children: [
PostsState,
CommentsState,
UsersState
],
})
@Injectable()
export class EntitiesState extends CrudEntitiesState { }The populate() route instruction
Getting every post's user
Getting one post's comments (via PopulationStrategy.ForeignId)
Last updated