Skip to content

RelationId breaks entity sorting #19

Open
@minmaxmean

Description

@minmaxmean

I have 2 entities: User and Follow, which is manual many-to-many relationship table. Both tables are identified by AdminBro and there are pages for them in navigation panel. But when I try to navigate to Follow page, it request fails with 500 error.

My debugging got me to find request failing in Core AdminBro package due to sortBy being undefined, because it could not find any property, by which is could sort.

Further digging got me to Property.isSortable() which apparently return false, even if my column is just a string or number. Which in turn, I think happens because typeorm marks my 2 primary columns as reference columns and admin-bro-typeorm` does not like that.

Is there any way of forcing adapter to sort by specified column or any other fix?
https://github.com/SoftwareBrothers/admin-bro-typeorm/blob/7ff78547db5eb0c8344692c92577a973593437d7/src/Property.ts#L28

image

Error: undefined column was not found in the Follow entity.
    at /home/m-nny/projects/junkyard/improved-spoon/src/find-options/FindOptionsUtils.ts:122:27
    at Array.forEach (<anonymous>)
    at Function.FindOptionsUtils.applyOptionsToQueryBuilder (/home/m-nny/projects/junkyard/improved-spoon/src/find-options/FindOptionsUtils.ts:118:40)
    at Function.FindOptionsUtils.applyFindManyOptionsOrConditionsToQueryBuilder (/home/m-nny/projects/junkyard/improved-spoon/src/find-options/FindOptionsUtils.ts:71:25)
    at EntityManager.<anonymous> (/home/m-nny/projects/junkyard/improved-spoon/src/entity-manager/EntityManager.ts:678:33)
    at step (/home/m-nny/projects/junkyard/improved-spoon/node_modules/tslib/tslib.js:143:27)
    at Object.next (/home/m-nny/projects/junkyard/improved-spoon/node_modules/tslib/tslib.js:124:57)
    at /home/m-nny/projects/junkyard/improved-spoon/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/home/m-nny/projects/junkyard/improved-spoon/node_modules/tslib/tslib.js:113:16)

Here are my entities. Also I created minimal repo (here)[https://github.com/m-nny/improved-spoon]

@Entity()
export class User extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  firstName: string;

  @Column()
  lastName: string;

  @OneToMany(() => Follow, (follow) => follow.followingUser)
  isFollowing?: Follow[];

  @OneToMany(() => Follow, (follow) => follow.followedUser)
  followedBy?: Follow[];
}
@Entity()
export class Follow extends BaseEntity {
  @PrimaryColumn()
  @RelationId((follow: Follow) => follow.followedUser)
  followedUserId: number;

  @PrimaryColumn()
  @RelationId((follow: Follow) => follow.followingUser)
  followingUserId: number;

  @ManyToOne(() => User, (user) => user.isFollowing)
  followingUser?: User;

  @ManyToOne(() => User, (user) => user.followedBy)
  followedUser?: User;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions