SoftwareBrothers / adminjs-typeorm

TypeORM adapter for AdminJS
MIT License
24 stars 32 forks source link

Relations dont show up in list, show and edit #18

Open in-live-md opened 3 years ago

in-live-md commented 3 years ago

on ver 1.4.0: I followed README and defined @RelationId() on my relation entities - but i cant get any relations to show up in adminbro UI. I can edit resources and set relations - and i can see in my logs the update sql is correct, but list, show and edit do not display the existing assigned relationships - tried with @admin-bro/typeorm@1.5.0-beta.2 as well.

show981111 commented 3 years ago

same. did you solve the problem? In my case, I can see the logs from TypeOrm select all columns, and I checked that admin-bro gets all the instances from find() at Resource but it is just not mapped to the UI. Also, if I change the variable name as the column name in the Database, then it works correctly. For example, in my Database, there is TEACHER table and it has a column, FK_TEACHER_teacherID. In my TEACHER entity, I had a member variable teacherID which refers to the "FK_TEACHER_teacherID." At this time, foreign key does not show up in the list, but if I change the name to FK_TEACHER_teacherID, then it shows up.

    @Column({ name: 'FK_TEACHER_teacherID' })
    @RelationId((teacher: Teacher) => teacher.teacher)
    @ApiProperty()
    teacherID: string; // if I change teacherID -> FK_TEACHER_teacherID, it works

    @ManyToOne((type) => TeacherID, (TeacherID) => TeacherID.teacherID, {
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE',
    })
    @JoinColumn({ name: 'FK_TEACHER_teacherID' })
    teacher: TeacherID;
es-lynn commented 2 years ago

Same problem here. It does not appear in the UI.

EDIT: So @show981111's advice is correct. I had to change my variable name to be exactly the same as the column name. Previously the variable name was named teacherId while the database table was named teacher_id, and AdminBro was not able to pick up the relation. After renaming the database table to be teacherId, it was able to work.

lolsborn commented 2 years ago

I'm having this problem, renaming columns to use the FK names seems not ideal, especially since this example isn't explicitly naming the FKs.