-
Notifications
You must be signed in to change notification settings - Fork 239
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
has_many through self_and_descendants #9
Comments
well, it's definitely not my day ;) class User < ActiveRecord::Base
has_many :contracts, finder_sql: proc {
Contract.where(user_id: self_and_descendant_ids).to_sql
}
end I'm sorry to have bothered you :) |
well, it isn't great (even good) solution, cause it doesn't work with default has_many behavior. has_many will use default query when for example User#contracts.where(foo: :bar) It should work just fine if self_and_descendants (and others) would be |
OK, I'll see how horrible it is (because I agree, your finder_sql is a nasty hack to have to do, and won't scale well). |
OK, try out 3.1.0 -- we're now using |
nice :) I'll try out new version withnin few days and I'll write is it working fine |
well, it does not work has_many :contracts, through: :self_and_descendants and i'm still getting
|
OK, I wrote an example in the specs and added support for your use case, but not using the has_many through, but by a different collection. This code is in 3.2.1.
How's that? |
I've got 2 models: User and Contract. User has many contracts but he should be able to see all of his and his descendants contracts. I tried something like this:
but i'm getting:
is it possible to do such thing?
The text was updated successfully, but these errors were encountered: