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

Error when sorting by an embedded entity while using join and skip/take #7079

Closed
18 of 21 tasks
H4kor opened this issue Nov 18, 2020 · 0 comments · Fixed by #7082, mattwelke/typeorm-postgres-example#165 or newerton/gobarber-2-backend#17

Comments

@H4kor
Copy link
Contributor

H4kor commented Nov 18, 2020

Issue Description

When trying to orderBy a column of an embedded entity the query fails while using take/skip and joining another.

        const result = await postRepo.createQueryBuilder("post")
            .leftJoinAndSelect("post.user", "user")
            .orderBy("post.blog.date")
            .take(2)
            .skip(1)
            .getMany();

Expected Behavior

It should be possible to sort by properties in embedded entities.

Actual Behavior

Error Message:

TypeError: Cannot read property 'databaseName' of undefined
      at /home/h4kor/code/ajai/typeorm/src/query-builder/SelectQueryBuilder.ts:2013:145

Steps to Reproduce

I will provide an Pull Request shortly.

Use the query above and executed with the entities below.

Entities:

import { Column, Entity, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "../../../src";


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

    @Column()
    name: string;

    @OneToMany(
        () => Post,
        (post) => post.user,
    )
    posts: Post[];
}

export class PublishInfo {
    @Column({ nullable: true })
    date: Date;
}

@Entity()
export class Post {
    @PrimaryGeneratedColumn()
    id: number;

    @Column()
    text: string;

    @Column(_type => PublishInfo)
    blog: PublishInfo;

    @Column(_type => PublishInfo)
    newsletter: PublishInfo;

    @ManyToOne(
        () => User,
        (user) => user.posts,
    )
    user: User
}

My Environment

Dependency Version
Operating System
Node.js version v12.16.2
Typescript version 3.6.0
TypeORM version 0.2.29 (master)

Additional Context

Relevant Database Driver(s)

  • aurora-data-api
  • aurora-data-api-pg
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time, and I know how to start.
  • Yes, I have the time, but I don't know how to start. I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment