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

Add Alias in Filter/Entity #1558

Open
samonkoba opened this issue Nov 23, 2022 · 0 comments
Open

Add Alias in Filter/Entity #1558

samonkoba opened this issue Nov 23, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@samonkoba
Copy link

Is your feature request related to a problem? Please describe.

I have an issue when trying to filter nested columns in the @authorize decorator.

ERROR [ExceptionsHandler] ER_NONUNIQ_TABLE: Not unique table/alias
@Authorize({
    authorize: (context: UserContext) => ({
        or:[
            {apartment: {owner: {agents: {agentId: {eq: context.req.user.id}}}}},
            {owner: {agents: {agentId: {eq: context.req.user.id}}}},
        ]
    } as unknown)
})

and was wondering whether we could have alias possibilities in the Filter functionality to enable us use Authorize or any other fllter feature without deeper customizations

Have you read the Contributing Guidelines?

Yes

Describe the solution you'd like

A solution would be

@Authorize({
    authorize: (context: UserContext) => ({
        or:[
            {apartment: {owner: {agents: {agentId: {eq: context.req.user.id}}, alias:"a_agents"}, alias:"a_owner"}}},
            {owner: {agents: {agentId: {eq: context.req.user.id}}, alias:"h_agents"}, alias:"h_owner"},
        ]
    } as unknown)
})

OR

@Authorize({
    authorize: (context: UserContext) => ({
        or:[
            {apartment: {"owner as apartment_owner": {"agents as apartment_agents": {agentId: {eq: context.req.user.id}}}}},
            {"owner as house_owner": {"agents as house_agents": {agentId: {eq: context.req.user.id}}}},
        ]
    } as unknown)
})

OR

    @JoinColumn({alias:"a_owner"})
    owner?: OwnerEntity;

The result would be to generate an SQL statement with a custom alias and ideally prevent multiple aliases when filtering with same entities and help alleviate the "Alias" issue reducing the workload for revamping whole modules

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Creating a custom resolver, however i will lose all the other necessary and crucial benefits that come with nestjs-query predefined setup

Additional context
Add any other context or screenshots about the feature request here.

Having multiple entities that share a third entity. Example; Either a house or an apartment can have an owner, while trying to filter owner house relationship one faces the error below.
ERROR [ExceptionsHandler] ER_NONUNIQ_TABLE: Not unique table/alias: 'owner'

@samonkoba samonkoba added the enhancement New feature or request label Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant