Skip to content

Add Alias in Filter/Entity #1558

@samonkoba

Description

@samonkoba

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions