adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Don't see properties in related field

Open Egor-Pizyk opened this issue 2 years ago • 2 comments

Hi everyone. I use adminJs with nestJs and typeorm. I have two entities - PostEntity and UserEntity. Each post (PostEntity) have an owner (UserEntity) with ManyToOne relation. When I connect PostEntity to adminJs I don't see anything in the owner column, but I expect that I can see id or user email. (Also I don't find in docs that is possible to show user email or user name or another fields from UserEntity. Is it possible?)

@Entity({ name: "post" })
export class PostEntity extends TimeStampEntity {
    @Column({ length: 255, unique: true })
    title: string;

    @Column()
    description: string;

    @Column({ default: 0 })
    likes: number;

    @ManyToOne((type) => UserEntity, (user) => user.posts)
    @JoinColumn({ name: "owner_id" })
    owner: UserEntity;

    @OneToMany((type) => ReviewEntity, (review) => review.post)
    reviews: ReviewEntity[];
}
@Entity({name: 'user'})
export class UserEntity extends TimeStampEntity{
    @PrimaryGeneratedColumn()
    id: number;

    @Column({name: 'user_name', nullable: true})
    userName: string;

    @Column({unique: true})
    email: string;

    @Column()
    password: string;

    @Column({name: 'is_active', default: true})
    isActive: boolean;

    @OneToMany((type) => PostEntity, (post) => post.owner)
    posts: PostEntity[]

    @OneToMany((type) => ReviewEntity, (review) => review.owner)
    reviews: ReviewEntity[]
}
export const postAdminResource = {
    resource: PostEntity,
    options: {
        navigation: postsNavigation,
        listProperties: ["id", "owner"],
    }
};
image

Egor-Pizyk avatar Aug 18 '23 19:08 Egor-Pizyk

Same issue, the reference column value does not show.

marksantoso avatar Dec 12 '23 00:12 marksantoso

You must explicitly define a @Column for your foreign key, for example (customerId):

  @ManyToOne('Customer', { eager: false, nullable: true, onDelete: 'CASCADE' })
  @JoinColumn({ name: 'customer_id' })
  public customer: Customer;

  @Column({ nullable: true })
  @RelationId((material: Material) => material.customer)
  public customerId: string;

dziraf avatar Dec 12 '23 06:12 dziraf