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

Cannot do nested join. #128

Closed
SzateX opened this issue Feb 13, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@SzateX
Copy link

commented Feb 13, 2019

Hi. I'm trying to do nested join of tables. But got error Error: nSQL: Where commands in a join must use the first table on the left side of the where query..

The example:
return await nSQL('PartnerStatus').query('select').join([ { type: 'left', table: 'Company', where: ['PartnerStatus.id', '=', 'Company.status'], }, { type: 'left', table: 'Picture', where: ['Company.picture', '=', 'Picture.id'], }, ]).exec();

I think it should do nested join with three tables.

I'm using v1 Api.

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented Feb 15, 2019

I don't think v1 or v2 have the ability to join tables like this. The second join in your example is using the results of the first join to join against.

Both systems are designed to allow you to join results against the main table, not join against the results of other joins.

return await nSQL('PartnerStatus').query('select').join([ 
    { 
        type: 'left', 
        table: 'Company', 
        where: ['PartnerStatus.id', '=', 'Company.status']
    }, 
    { // joining against results of above join, not against a column in "PartnerStatus" table.
        type: 'left', 
        table: 'Picture', 
        where: ['Company.picture', '=', 'Picture.id'], 
    }
]).exec();

I'll take a look at the source code for v1 and v2 and see what it would take to support this.

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented Feb 17, 2019

Okay, this is doable in 2.2.0, released today.

To get this to work in v1 is going to take refactoring the v1 join code to work like the v2 joins, it's a bit involved so it might be a while before I can get to it.

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented May 21, 2019

Refactoring the version 1 code is far more complicated than I had expected, it's going to end up needing to rewrite most of the version 1 query code to make it work.

I'm going to close this issue for now, I'm not sure the development resources are worth it to get this feature into v1. If there are other folks who want this feature in v1 then +1 this comment to let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.