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

shall use leftJoin by default and support on clause #98

Closed
Diluka opened this issue Jun 13, 2019 · 12 comments
Closed

shall use leftJoin by default and support on clause #98

Diluka opened this issue Jun 13, 2019 · 12 comments

Comments

@Diluka
Copy link
Contributor

Diluka commented Jun 13, 2019

private getJoinType(relationType: string): string {
switch (relationType) {
case 'many-to-one':
case 'one-to-one':
return 'innerJoin';
default:
return 'leftJoin';
}
}

shall use leftJoin by default and use innerJoin by config
see sequelize options include.required behavior

If the relation can be set NULL, innerJoin will break the query.

refer: http://docs.sequelizejs.com/class/lib/model.js~Model.html#static-method-findAll

Name Type Attribute Description
options.include[].required boolean optional If true, converts to an inner join, which means that the parent model will only be loaded if it has any matching children. True if include.where is set, false otherwise.
@michaelyali
Copy link
Member

michaelyali commented Jun 13, 2019

Ok, let's make it be leftJoin by default, and add required: boolean as an option.
@Diluka would you like to make a PR? :) just asking. I can do it on my own

@Diluka
Copy link
Contributor Author

Diluka commented Jun 13, 2019

export type QueryJoin = {
  field: string;
  select?: QueryFields;
  required?: boolean; // <-- add here?
  on?: string; // <-- maybe this together?
};

You do this PR is better. I need to take the time to familiarize myself with this new architecture.

When using left join and the relation can be set null, the same condition put in on or where can be different result.

p.s. I feel that it will become more and more complicated here.

@macchie
Copy link

macchie commented Jun 14, 2019

UP! We had the same problem here :D

@Diluka Diluka changed the title shall use leftJoin by default shall use leftJoin by default and support on clause Jun 21, 2019
@michaelyali
Copy link
Member

@Diluka @macchie this will have a high priority on the next release.

@macchie
Copy link

macchie commented Jul 4, 2019

@Diluka @macchie this will have a high priority on the next release.

thanks! Great project!

@Diluka
Copy link
Contributor Author

Diluka commented Jul 8, 2019

does this related to #31 ? @zMotivat0r

@michaelyali
Copy link
Member

yep

@MeMeMax
Copy link

MeMeMax commented Aug 25, 2019

Is it correct that I can´t get e.g. only the data of the currently logged in user by now with the config options given or am I missing anything?

@sergak01
Copy link

UP! I have the same problem!

@Bnaya
Copy link

Bnaya commented Sep 10, 2019

See possible workaround:
#31 (comment)

michaelyali added a commit that referenced this issue Oct 2, 2019
Fixed using left join by default. Added "required" param to the join options

fix #31, #98
@cuni0716
Copy link

Not released yet @zmotivator?

@0x7061
Copy link

0x7061 commented Nov 11, 2021

Has the on= config been ignored? I think this might be useful nevertheless.

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

No branches or pull requests

8 participants