Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RelationId breaks entity sorting #19

Open
minmaxmean opened this issue May 3, 2021 · 1 comment
Open

RelationId breaks entity sorting #19

minmaxmean opened this issue May 3, 2021 · 1 comment

Comments

@minmaxmean
Copy link

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;
}
@dziraf
Copy link

dziraf commented Feb 24, 2022

Does the problem still persist in the latest version of the adapter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants