Skip to content

Fixes #29#31

Draft
blitzmann wants to merge 5 commits into
andryuha49:masterfrom
blitzmann:issue-pr/29
Draft

Fixes #29#31
blitzmann wants to merge 5 commits into
andryuha49:masterfrom
blitzmann:issue-pr/29

Conversation

@blitzmann
Copy link
Copy Markdown
Contributor

@blitzmann blitzmann commented Jun 22, 2021

Fixes #29, Requires #28 as I used it's sorted evaluation.

Essentially, this changes the way alias's work. We no longer assume the alias = the navigation property, because in that scenerio you can't join two two or more of the same table. This PR changes the alias to be the property, plus the current position of the token, which should make them all unique since tokens can't share the same position, and it also gives helpful debugging information right there in the alias name.

Also fixes an issue with having a , missed.

Unfortunately, I don't really have a good test of this at the moment. I used my own test entities, but it doesn't make sense in this repo. I will try to add actual test cases to the example server.

Additionally, it's getting harder to split these changes up into PR's from my other improvements. I would love to continue to contribute, but if this project is no longer maintained, then please mention that on the README and I won't have to make the effort. But as it stands now, I might not be able to continue to move forward with additional PRs without them stepping on one another

Testing

  • Pull master 9985f6c
  • Cherry pick d27b91 from this PR. This will give you new entities configured in a way that will show this problem
  • Run pre-fix
  • checkout PR's HEAD
  • Run post-fix

The new entities are: User, and PostComment. A post has several comments, and each comment is associated with a User. Additionally, the Author now is associated with a User.

Pre-fix

Start the example server with the new entities and migration, and then run this:
{{base_url}}/api/posts?$select=id,title&$expand=author($expand=user),comments($expand=user)&$filter=id eq 1

{
    "message": "Internal server error.",
    "error": {
        "message": "SQLITE_ERROR: ambiguous column name: user.id"
    }
}

This is because we're trying to expand a user property twice - once in author, and once in comments. Since we use the property path as the alias, there's two joins with the alias of user

Post-fix

We can now bring back user relations for both author and all the comments. This is because we change the alias that is used to be unique to that specific expansion

{{base_url}}/api/posts?$select=id,title&$expand=author($expand=user),comments($expand=user)&$filter=id eq 1

[
    {
        "id": 1,
        "title": "Ultricies Sem Ltd",
        "author": {
            "id": 1,
            "name": "Ursula Manning",
            "user": {
                "id": 1,
                "username": "a_manning_ursula"
            }
        },
        "comments": [
            {
                "id": 1,
                "comment": "Nulla nec feugiat metus, ut condimentum nisi. Vestibulum ac velit.",
                "user": {
                    "id": 6,
                    "username": "user_1"
                }
            },
            {
                "id": 2,
                "comment": "In consequat at neque pharetra rutrum. Curabitur rutrum mi sem.",
                "user": {
                    "id": 6,
                    "username": "user_1"
                }
            },
            {
                "id": 3,
                "comment": "Nulla facilisi. Cras vestibulum dictum dui bibendum maximus. Nullam eu.",
                "user": {
                    "id": 8,
                    "username": "user_3"
                }
            },
            {
                "id": 4,
                "comment": "Pellentesque habitant morbi tristique senectus et netus et malesuada fames.",
                "user": {
                    "id": 7,
                    "username": "user_2"
                }
            },
            {
                "id": 5,
                "comment": "Sed rutrum pretium nunc nec condimentum. Proin non orci imperdiet.",
                "user": {
                    "id": 6,
                    "username": "user_1"
                }
            }
        ]
    }
]

Here we identify the node that filters on something like posts/id, and sets the relation in the included so that data can be pulled back without expand.

There is currently a bug tho - if the filter comes before the expand, the expand doesn't set the selections correctly. This is due to us already having visited the table with the filter, and setting select = '' (hardcoded)
(cherry picked from commit 0ef5c0a)
…d filter inclusions for select alias processing)

* Remove `expands` property - Not entirely sure the purpose of this, looks like it was supposed to work similar in that it was storing selections that needed to be expanded first, and then adding them during the expansion
* Fixed bug where a `,` was being missed while adding to `this.select`

(cherry picked from commit 78f4c5d)
(cherry picked from commit 7f29553)

# Conflicts:
#	examples/server/src/migrations/1577087002356-dataFilling.ts
#	examples/server/src/server.ts
@blitzmann
Copy link
Copy Markdown
Contributor Author

@andryuha49 I added what I hope are simple testing instructions. :)

@blitzmann
Copy link
Copy Markdown
Contributor Author

@andryuha49 when do we think we can review this PR? This one is actively blocking some of our development, so want to make the review as smooth as possible, anything I can do to help?

@andryuha49 andryuha49 mentioned this pull request Jun 29, 2021
@blitzmann
Copy link
Copy Markdown
Contributor Author

@andryuha49 I believe I found an issue with this PR in my other work. While the alias is being set correctly, if you filter on that relationship, then the filter does not reflect that new alias, and instead it is shown as the original name. I don't have a good test / example of this at the moment, but I'll try to dig into soon. I'm going to change this PR to a draft in the meantime

@blitzmann blitzmann marked this pull request as draft July 1, 2021 00:09
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

Successfully merging this pull request may close these issues.

Cannot expand relations when they share a relation

1 participant