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 for Join and Query main array. #43

Open
mahdiaslami opened this issue Jun 20, 2022 · 0 comments
Open

Add alias for Join and Query main array. #43

mahdiaslami opened this issue Jun 20, 2022 · 0 comments

Comments

@mahdiaslami
Copy link
Owner

Problem

  • What should we do to prevent overwriting properties?
  • How should we compare two columns with the same name?

1. Force using an alias in join.

query(childs)
    .join(parents, 'p')
        .on('parent_id').col.equal('p.id')
    .get()

And result is like:

const r = {
    id: 1,
    name: 'foo',
    /* [[OTHER CHILD PROPS]] */

    p: {
        id: 2,
        name: 'bar',
        /* [[OTHER PARENT PROPS]] */
    }
}

2. Force using an alias for join and query when using join.

query(childs, 'c')
    .join(parents, 'p')
        .on('c.parent_id').col.equal('p.id')
    .get()

And result is like:

const r = {
    c: {
        id: 1,
        name: 'foo',
        /* [[OTHER CHILD PROPS]] */
    },
    
    p: {
        id: 2,
        name: 'bar',
        /* [[OTHER PARENT PROPS]] */
    }
}

3. Implement both ways 1 and 2, And make them optional.

  • If a developer does not provide both aliases, overwrite columns with the same name.
  • When the column name in the on() method is the same as the column name in the on().col.<condition>() method then the first column always belongs to the main array. and the second column always belongs to the joined array.

Reference: #32 (comment)

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

No branches or pull requests

1 participant