nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.09k stars 539 forks source link

[Feature Request] Join Filter (in ON clause) #562

Open bestickley opened 4 years ago

bestickley commented 4 years ago

This would allow a user to specify a WHERE condition in an ON clause when joining a relation. This could be added on the QueryJoin type in @nestjsx/crud-request like so:

export declare type QueryJoin = {
    field: string;
    select?: QueryFields;
    onFilter: QueryFilter;
};

A joinType could also be added to onFilter to specify left or inner join. Currently, there is no way to filter on just a relation (it affects the base entity) so this feature would fill that hole.

zealotrahl commented 3 years ago

I encountered the problem, I have a parent entity, and one to many child entities, I do join children eager in the controller, and filter children by some attribute, children.status != deleted, as a result if some (not all) children entities have such status, the parent entity is being filtered out. So are you looking into the same issue?

sokhorn-houn commented 3 years ago

This would allow a user to specify a WHERE condition in an ON clause when joining a relation. This could be added on the QueryJoin type in @nestjsx/crud-request like so:

export declare type QueryJoin = {
    field: string;
    select?: QueryFields;
    onFilter: QueryFilter;
};

A joinType could also be added to onFilter to specify left or inner join. Currently, there is no way to filter on just a relation (it affects the base entity) so this feature would fill that hole.

@bestickley I'm looking solution to this problem too. Could you advise the solution? I'm trying to customize builder.addSelect(select) in setJoin function.

bestickley commented 3 years ago

@sokhorn-houn, unfortunately this isn't possible right now. I just brought it up as a feature request.

sokhorn-houn commented 3 years ago

@sokhorn-houn, unfortunately this isn't possible right now. I just brought it up as a feature request.

@bestickley thank you so much.