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

$joinRelation forces inner join - is there a $leftJoinRelation? #143

Open
pskfry opened this issue Mar 10, 2021 · 7 comments
Open

$joinRelation forces inner join - is there a $leftJoinRelation? #143

pskfry opened this issue Mar 10, 2021 · 7 comments

Comments

@pskfry
Copy link

pskfry commented Mar 10, 2021

hello all - first of all thank you for the work you do it is greatly appreciated.

the issue i'm having is pretty straightforward. i have a complex graph query that utilizes $joinRelation to join a few nested relations which is working great.

the only issue i'm having is that it's using an inner join under the hood and i'd very much prefer it to be using a left join. is this possible? for the record, what i'm doing cannot be accomplished with $eager alone - i need $joinRelation because i need to also filter based on the relation's value. here's what the query looks like:

Person {
  name: string;
  job: Job; // Model.BelongsToOneRelation
}

Job {
  title: string;
  skill: Skill; // Model.BelongsToOneRelation
}

Skill {
  name: string;
}
api.services("persons").find({
  query: {
    $eager: "[job.[skill]]"
    $joinRelation: "[job.[skill]]"
  }
});

So currently, if a given Person does not have a Job, or they have a Job and that Job does not have a Skill, that Person will not show up in the query results. The reason I need $joinRelation is so I can do this (which works great!):

api.services("persons").find({
  query: {
    $eager: "[job.[skill]]",
    $joinRelation: "[job.[skill]]",
    "job:skill.name": userInputtedSkill
  }
});

I tried $leftJoinRelation with no luck - I also tried eagerOptions in the service options but Typescript wouldn't accept the property. Any help is greatly appreciated!

@dekelev
Copy link
Member

dekelev commented Mar 10, 2021 via email

@jf250315
Copy link

thanks for the speedy response - i will try this tonight. i tried using $modifyEager first before $joinRelation but couldn't get it to work - but i know more about how to write these queries now so i'll try it again and let you know.

@pskfry
Copy link
Author

pskfry commented Mar 11, 2021

well - i just spent a few hours trying to get modifiers to work the way i want them to, but it just messed with the pagination mechanism so much that i think i need to do some minor refactoring.

i suppose this is why the objection documentation warns us that graph queries are not a silver bullet!

@dekelev
Copy link
Member

dekelev commented Mar 11, 2021 via email

@dekelev
Copy link
Member

dekelev commented Mar 11, 2021 via email

@wz5899
Copy link
Contributor

wz5899 commented Sep 11, 2022

I added the $leftJoinRelation and submitted a pull request #182 .

@sokulski
Copy link

well - i just spent a few hours trying to get modifiers to work the way i want them to, but it just messed with the pagination mechanism so much that i think i need to do some minor refactoring.

Did you ever end up finding a way to make this work?

@wz5899's $leftJoinRelation seems promising. I've been wracking my brain trying to get $modifyEager to work, but I can only seem to get it to modify which children appear in the relationship, not which parents.

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

5 participants