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

One-To-Many / Many-To-One cannot be query/joined #779

Open
ghostlexly opened this issue Apr 16, 2022 · 3 comments
Open

One-To-Many / Many-To-One cannot be query/joined #779

ghostlexly opened this issue Apr 16, 2022 · 3 comments

Comments

@ghostlexly
Copy link

ghostlexly commented Apr 16, 2022

Hello, i'm new on nestjs,
i have an issue with the join of these two entities, can't find why...
any help ?..

Controller

@Crud({
  model: {
    type: Housekeeper,
  },
  query: {
    join: {
      geozones: {
        alias: "test",
        allow: ["postalCode"],
        eager: true,
      },
    },
  },
})
@ApiTags("housekeepers")
@Controller("housekeepers")
export class HousekeepersController implements CrudController<Housekeeper> {

Geozone.ts

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

  @IsDefined()
  @Validate(RelationExists, [{ targetEntity: "housekeeper", targetField: "id" }])
  @ApiProperty({ type: "number" })
  @ManyToOne(() => Housekeeper, (hs) => hs.geozones)
  @JoinColumn()
  owner: Housekeeper;

  @ApiProperty()
  @Column()
  postalCode: string;
}

Housekeeper.ts

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

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

  @OneToMany(() => Geozone, (geozone) => geozone.owner)
  geozones: Geozone[];
}

Here is the error:

backend_1       | [Nest] 2197  - 04/16/2022, 6:27:43 PM     LOG [NestApplication] Nest application successfully started +1ms
backend_1       | [Nest] 2197  - 04/16/2022, 6:28:24 PM   ERROR [ExceptionsHandler] Duplicate column name 'Housekeeper_id'
backend_1       | QueryFailedError: Duplicate column name 'Housekeeper_id'
backend_1       |     at Query.onResult (/usr/src/app/src/driver/mysql/MysqlQueryRunner.ts:222:33)
backend_1       |     at Query.execute (/usr/src/app/node_modules/mysql2/lib/commands/command.js:36:14)
backend_1       |     at PoolConnection.handlePacket (/usr/src/app/node_modules/mysql2/lib/connection.js:456:32)
backend_1       |     at PacketParser.onPacket (/usr/src/app/node_modules/mysql2/lib/connection.js:85:12)
backend_1       |     at PacketParser.executeStart (/usr/src/app/node_modules/mysql2/lib/packet_parser.js:75:16)
backend_1       |     at Socket.<anonymous> (/usr/src/app/node_modules/mysql2/lib/connection.js:92:25)
backend_1       |     at Socket.emit (node:events:390:28)
backend_1       |     at addChunk (node:internal/streams/readable:315:12)
backend_1       |     at readableAddChunk (node:internal/streams/readable:289:9)
backend_1       |     at Socket.Readable.push (node:internal/streams/readable:228:10)

update:
i found that this issue appears only when "limit" or "maxLimit" is set in query.

@ludovit-ubrezi
Copy link

Did you found out how it can be used with limit? Because it is basic paging functionality ... trying to tag team member @fwoelffel

@zetti-caletti
Copy link

zetti-caletti commented Oct 13, 2022

Have same problem. It appears if limit is set. I have made a PR: #808

@Kannan18Msc
Copy link

Kannan18Msc commented Mar 6, 2024

please try as it is entities field name @ghostlexly
Screenshot 2024-03-06 at 2 34 00 PM
Screenshot 2024-03-06 at 2 35 49 PM

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

4 participants