SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.15k stars 659 forks source link

Don't see properties in related field #1551

Closed Egor-Pizyk closed 5 months ago

Egor-Pizyk commented 1 year ago

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
marksantoso commented 8 months ago

Same issue, the reference column value does not show.

dziraf commented 8 months ago

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;