question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Join conditions on entity relation

See original GitHub issue

Is it possible to define a custom join condition for an entity relation? Some pseudo code to illustrate the intent.


type Position = 'pg' | 'sg' | 'sf' | 'pf' | 'c';

class Player {
    id: number;
    name: string;
    position: Position;
    teamId: number
    @ManyToOne(type => Team, team => team.players)
    team: Team;
}

class Team {
    id: number;
    @OneToMany(type => Player, player => player.team)
    @JoinCondition('team.players','shootingGuards','players.teamId = team.id and players.position = "sg"')
    shootingGuards: Player[]
}

I know this is possible through the querybuilder, but looking at the docs there does not seem to be a way to define something like this on the entities itself

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
whizpahcommented, Aug 19, 2019

This is a feature I would really like to see. Any updates on if it’s planned for implementation?

2reactions
chetanismcommented, Dec 17, 2021

+1 Leaving my use case here:

class Account {
  @PrimaryGeneratedColumn()
  id: number;

  @OneToMany(() => AccountUser, (user) => user.account)
  users: Promise<AccountUser[]>

  @OneToOne(() => AccountUser, (admin) => admin.account, {
    where: { isAdmin: true },   // --> Would be great to be able to specify such a condition somehow
  })
  admin: Promise<AccountUser>
}

class AccountUser {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  isAdmin: boolean;

  @ManyToOne(() => Account, (account) => account.users)
  account: Promise<Account>;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

JOIN Relationships and JOINing Tables - The Data School
A JOIN SQL statement combines two data from two tables together. In this interactive SQL tutorial, learn the most common JOIN statements.
Read more >
Concepts → Join Condition
A join condition defines the relationship between a physical schema entity object and itself (self-join) or the relationship between two entity objects: a ......
Read more >
How to specify several join conditions for 1:1 relationship in ...
Have you tried to specify second join column with columnDefinition="enum('YOUR_CONSTANT')") ? · You can use queryBuilder when making the query ?
Read more >
Configuring how Relationship Joins
Specifying Alternate Join Conditions¶ ... The default behavior of relationship() when constructing a join is that it equates the value of primary key...
Read more >
Join Query In Entity Framework - TekTutorialsHub
The next two arguments specify the condition on which you want to join the tables. The first object is from the outer table...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found