Comments (25)
Is this still an issue in Rails 5.1? I'm going to help keep this project maintained and I want to fix what's broken and make sure we can support Rails 5.2 now that it is out.
from activerecord-hierarchical_query.
Sounds fair. It is going to take me a little longer to reproduce again as I'm fixing some conflicts in the branch I was working in. I'll re-open the issue when it gets to that point.
from activerecord-hierarchical_query.
It's start_with
method which generates an error. I don't know why.
Only variable $2 (LIMIT) is taken into account.
from activerecord-hierarchical_query.
Try to replace start_with(id: id)
by start_with(YourModel.find(id))
or start_with(self)
from activerecord-hierarchical_query.
I see the same problem. If I try to give the object as an argument to start_with, it ignores the condition
from activerecord-hierarchical_query.
It appears that when chaining with other queries, the argument list gets replaced
from activerecord-hierarchical_query.
A workaround similar to the one mention in rails/rails#20077 (comment) worked for me
from activerecord-hierarchical_query.
@zachaysan I would suspect so. One of the reasons I'm still stuck on Rails 4.2 is because I couldn't upgrade activerecord-hierarchical_query without issues like this when attempting a Rails 5 upgrade, so if you're looking to help fix and maintain, I would be happy to help you and do testing and try a Rails 5 upgrade again. Not sure on the time frame though due to work responsibilities.
from activerecord-hierarchical_query.
Great @xtagon I don't want you to waste time so if you could just give me a detailed, but austere way of replicating the bug I'll try to handle as soon as possible.
from activerecord-hierarchical_query.
@zachaysan I'll have to pull my Rails 5 upgrade branch and see if I can reproduce. There have been a lot of changes to my own app since I last tried the upgrade. I'll try to do it this weekend. Thanks so much for the help!
from activerecord-hierarchical_query.
Hey @xtagon I'm going to close this issue. If you can re-produce in 1.1.0 let me know, but I'm currently unable to.
from activerecord-hierarchical_query.
@zachaysan Just to let you know, I reproduced this on 1.1.0 and Rails 5.0, but this time when I changed start_with
to use self
instead of the model ID, it fixed it. Awesome!
Thanks again for everyone's help.
from activerecord-hierarchical_query.
@xtagon Dang really? What happens if you do self.id
?
from activerecord-hierarchical_query.
If I pass the ID it has a prepared statement error like the one I originally shared. If I pass the model object it works. I think if I pass an array of multiple IDs it works too.
from activerecord-hierarchical_query.
I'm trying to make sure it's not related to some id weirdness. Sometimes ids are strings in rails and sometimes they're integers.
What happens if you do this:
relation = self.class.join_recursive do |query|
query.start_with(id: self.id).connect_by(parent_organization_id: :id)
end
from activerecord-hierarchical_query.
Here is part of the code that I got the error from:
relation = self.class.join_recursive do |query|
query.
start_with(id: self.id) { select("0 depth") }.
select(query.prior[:depth] + 1, start_with: false).
connect_by(id: :parent_organization_id)
end
It only causes an error if you do a where
condition or similar later on this relation as described above. If you do a to_a
directly on it it's fine. Replacing self.id
with self
fixes it too.
I didn't think of this before but I am using Postgres GUID strings as IDs if that helps.
from activerecord-hierarchical_query.
Hmm. I'm going to bet that GUID is why I can't seem to replicate because I'm not currently using them and they're another tricky case of sometimes integer, sometimes string tomfoolery.
Are you able to clone the repo and run the tests? Could you create a failing tests with a GUID column? If you can do that I'll try to figure out the root cause.
from activerecord-hierarchical_query.
I'll give it a shot.
from activerecord-hierarchical_query.
All tests pass when I switch your test schema to use UUIDs. I even added a test case that looks as close as possible to the one in my app (I am not able to give access to my app's source unfortunately).
Very strange, I'm not sure why it won't reproduce.
I made sure to use the Rails 5.0 gemfile too.
from activerecord-hierarchical_query.
Hmmm. Are you using any weird default scopes or redefining any core methods?
from activerecord-hierarchical_query.
I am using this soft deletion gem on the model, which adds a default scope for deleted_at IS NULL
: https://rubygems.org/gems/soft_deletion
from activerecord-hierarchical_query.
Sorry for the delay. Does disabling the gem do anything? I dislike uncertainty and spookiness in libraries so I'd like to figure out what is wrong.
from activerecord-hierarchical_query.
Just tried that, it didn't seem to have an effect.
This is on Rails 5.0.0 - I'm going to be upgrading to 5.1 and then 5.2 soon-ish, maybe it was something that changed in Arel
from activerecord-hierarchical_query.
I'd like to figure out what is wrong too, but just to clarify I'm perfectly fine with the workaround of using the record instance -- it doesn't solve the mystery but it solves my use case
from activerecord-hierarchical_query.
Well if it is still an issue in 5.2 then I'm going to try to figure it out. Partially for my own interests. I want to be able to rely on this library in production and I generate some pretty abstract queries during a request cycle so this needs to be dependable.
from activerecord-hierarchical_query.
Related Issues (19)
- Add support for Rails 5.0 HOT 2
- Column name 'parent' replaces automatically to 'parent_id' HOT 2
- require statement HOT 2
- Error: undefined method `bound_attributes` for ActiveRecord::Relation HOT 23
- Rails 5.1 support HOT 4
- LTree Support? HOT 2
- pg ~>1.0 support HOT 2
- Rails 6 HOT 9
- PG 1.2.x Support HOT 4
- Error: bind message supplies 2 parameters, but prepared statement requires 1 HOT 8
- NOCYCLE query with DISTINCT clause returns extremely long result set HOT 5
- Having syntax errors with this gem HOT 8
- Incompatible to Rails 6.1 HOT 1
- Rails 7? HOT 4
- pg-1.4 HOT 4
- recursive has_many queries
- No tag for 1.4.3 release HOT 1
- to_hash HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from activerecord-hierarchical_query.