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

Invalid SQL in relative_rank when order column value is nil #177

Open
mattvague opened this issue Jun 1, 2021 · 1 comment
Open

Invalid SQL in relative_rank when order column value is nil #177

mattvague opened this issue Jun 1, 2021 · 1 comment

Comments

@mattvague
Copy link

If you have a model with nil as the position in the database, calling model. branch_order_rank will raise an error due to invalid SQL, eg:

ActiveRecord::StatementInvalid Exception: PG::SyntaxError: ERROR:  syntax error at or near ")"
LINE 1: ... AND "relationship_nodes"."id" != $3 AND ("branch_order" < )

I think I've narrowed down this issue to this method.I know that ranked-model attempts to always populate the column on save but it's possible if you have an existing dataset, bypass callbacks, that you could still have nil values making this an issue.

Not sure what the right solution is, but I feel like this situation should be gracefully handled somehow. Happy to open a PR with a little guidance. Thanks!

@mattvague mattvague changed the title Invalid SQL in relative_rank when column is nil Invalid SQL in relative_rank when order column is nil Jun 1, 2021
@mattvague mattvague changed the title Invalid SQL in relative_rank when order column is nil Invalid SQL in relative_rank when order column value is nil Jun 1, 2021
@brendon
Copy link
Owner

brendon commented Jun 1, 2021

Hi @mattvague, I'm not too sure what to do about this. It looks like you're explicit calling branch_order_rank on this item? Perhaps you could check if the branch_order is nil first?

If that's not the code path then I'd be keen to know what it is to see if we can cope.

My suggestion would be to add mechanisms on your end to keep your data clean (if it has a tendency to get out of order). If you don't bypass the callbacks and ensure any existing data is fixed up before using ranked-model you should have a better time :)

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

2 participants