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

ER_DUP_FIELDNAME while using querybuilder with join in v3.1.3 #633

Open
shashi-3dqr opened this issue Oct 26, 2021 · 3 comments
Open

ER_DUP_FIELDNAME while using querybuilder with join in v3.1.3 #633

shashi-3dqr opened this issue Oct 26, 2021 · 3 comments

Comments

@shashi-3dqr
Copy link

shashi-3dqr commented Oct 26, 2021

The below error occurs while using a query builder with join (tried inner and left join). And, this occurs only in v3.1.3 and not in v3.1.2.

code: 'ER_DUP_FIELDNAME',
errno: 1060,
sqlState: '42S21',
sqlMessage: "Duplicate column name 'id'",
query: 'SELECT COUNT(*) AS `value` FROM (SELECT * FROM `code` `c` INNER JOIN `user` `u` ON `u`.`id`=`c`.`userId` ORDER BY `c`.`id` DESC) `uniqueTableAlias`',
  parameters: []
@bashleigh
Copy link
Collaborator

I don't see a duplication? That's odd. Mind sharing with me your pagination func usage?

@shashi-3dqr
Copy link
Author

const paginationOptions = {
  page: 1,
  limit: 10,
  route: '',
  routingLabels: { limitLabel: 'itemsPerPage', pageLabel: 'currentPage' }
};

const queryBuilder = this.codesRepository
  .createQueryBuilder('c')
  .innerJoinAndSelect('c.user', 'u')
  .orderBy('c.id', 'DESC');
        
 const page = await paginate<CodeEntity>(
   queryBuilder,
   paginationOptions,
 );

Entities:

export class CodeEntity extends AbstractEntity {
  @Column()
  text: string;

  @ManyToOne(() => UserEntity, { onDelete: 'CASCADE' })
  user: UserEntity;

  constructor(entity?: Partial<CodeEntity>) {
    super(entity);
  }
}

export class UserEntity extends AbstractEntity {
  @Column({ unique: true, nullable: true })
  username: string;

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

  @Column()
  password: string;

  constructor(entity?: Partial<UserEntity>) {
    super(entity);
  }
}

export abstract class AbstractEntity {
  @PrimaryGeneratedColumn({ type: 'int', unsigned: false })
  id: number;

  @CreateDateColumn({ nullable: true })
  createdAt: Date;

  @UpdateDateColumn({ nullable: true })
  updatedAt: Date;

  protected constructor(entity?: Partial<AbstractEntity>) {
    if (entity) {
      Object.assign(this, entity);
    }
  }
}

@bashleigh
Copy link
Collaborator

ahhh I see it now. SELECT * is not aliases. Annoying

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