Skip to content

Query for relation of relation fails. #4787

Closed

Description

@jgunn987

Issue type:

[ ] question
[x ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[x ] @next
[ ] 0.x.x (or put your version here)

I am having trouble retrieving a relation of a relation in a find query.
Below is my query,

export async function getProfile({ db }, { params: { uid }, query }, res) {
  const profile = await db.manager
    .getRepository(Profile)
    .findOne({
      where: { uid },
      relations: [
        'grantedRewards',
        'grantedRewards.reward',
      ]
    });
  //...
}

Here are the entities i am querying,

@Entity()
export class Profile {
  //...
  @OneToMany(type => RewardGrant, grant => grant.profile, {
    cascade: true
  })
  grantedRewards: RewardGrant;
}
@Entity()
export class RewardGrant {
  //...
  @ManyToOne(type => Profile, profile => profile.grantedRewards, { nullable: false })
  profile: Profile;

  @ManyToOne(type => Reward, { nullable: false, onDelete: 'CASCADE' })
  @JoinColumn()
  reward: Reward;

}

This is the error is get on execution

(node:28140) UnhandledPromiseRejectionWarning: Error: Property "grantedRewards.reward" was not found in Profile. Make sure your query is correct.

Any help here would be much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions