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

Fix #leaves used with a custom relation #29

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

attilahorvath
Copy link
Contributor

Currently #leaves doesn't work properly with chained custom relations.

The #where_values_hash method used in its implementation doesn't return every where condition, e.g. it ignores the ones passed as raw SQL fragment strings, leading to an empty hash which then causes the method to just return an empty array.

Here is a test case to illustrate the issue:

TreeNode.where("path <> 'Top.Collections.Pictures.Astronomy.Stars'")
        .leaves
        .pluck(:path) #=> []

This PR fixes the issue by rewriting the query to check for leaf nodes based on https://stackoverflow.com/a/43512352.

@sjke sjke merged commit c3c04d7 into sjke:master Dec 13, 2019
@sjke
Copy link
Owner

sjke commented Dec 13, 2019

@attilahorvath thx for your fix.

@attilahorvath attilahorvath deleted the fix-leaves-with-relations branch December 13, 2019 10:00
sjke added a commit that referenced this pull request Nov 10, 2022
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.

2 participants