-
-
Notifications
You must be signed in to change notification settings - Fork 829
Support nested children in Arel::Nodes::And
#1279
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
Conversation
Arel::Nodes::And
This looks great but do we have test coverage? |
Nope, also I tried to reproduce the issue and couldn't. |
@ciihla thank you for this contribution, is it possible to add a test (that would fail first without your PR) ? |
The test is very specific, maybe it has to do something with combination of multitenancy(
error:
Sorry I dont have much time to elaborate more :( |
Thanks @ciihla, it definitely makes sense to me that a third gem is involved here. If you find time to isolate this to a sample app, it'd be great. Even temporarily removing either of these gems from your application to see if the issue still reproduces and further isolate the culprit would be great. |
f8fb6e2
to
a02daba
Compare
We encountered another use case that this patch seems to fix: querying a scoped association where the association model also has a default scope (multiple conditions). Here is a standalone test that exposes the error, and a copy with the patch applied that executes without error. Here is another example reproducing the failure with a different set of conditions. |
@shannondoah I just ran into this same issue, have you been running this patch in production? |
@tappleby No, we haven't. For the use case we encountered initially, we swapped out ransack's |
We also run into this problem while using # This results in NoMethodError
ActsAsTenant.with_tenant(Tenant.first) { Job.ransack({"entity_tags_tag_id_not_in"=>["1"]}).result.to_a }
# This works fine
ActsAsTenant.without_tenant { Job.ransack({"entity_tags_tag_id_not_in"=>["1"]}).result.to_a } It'd be great to see this PR merged. For now, we'll use an override similar to what @shannondoah described. |
I'm running into this issue when filtering by an associated attribute (many-to-many) using negative matchers like not_in or not_null. After applying the suggested changes, I hit a different problem: the This causes the following error: undefined method 'eq' for an instance of Array Any idea how we could handle this case? |
Just wanted to chime in here and say: This PR has fixed the same error as in #925 for me, however I also have a fairly complex case: I am using acts_as_taggable_on and want to search for records which do not have a specific tag at all among their tags. I am doing this by using a field of If necessary I can try to write a test case, let me know! |
@phikes it may help to fix it :) So if you going to do it, keep me posted, I am happy to look into that too. |
Thanks for coming back to me, @bopm and thanks for working on this :-). I did not. I monkey patched the changes from this PR. I can try to wok on a test case tomorrow. Without looking into the code: Do you happen to know if the codebase already depends on the acts_as_taggable gem for development? That would probably make it very easy to construct the very same test case. |
@phikes two thoughts here:
ransacker :tagged_ids do |parent|
tagging_table = ActsAsTaggableOn::Tagging.arel_table
tag_table = ActsAsTaggableOn::Tag.arel_table
Arel::Nodes::Grouping.new(
tagging_table
.join(tag_table)
.on(tag_table[:id].eq(tagging_table[:tag_id]))
.where(
tagging_table[:taggable_type].eq(base_class.name)
.and(tagging_table[:taggable_id].eq(parent.table[:id]))
.and(tag_table[:identifies_id].eq(parent.table[:org_id]))
.and(tag_table[:identifies_type].eq(Org.to_s)),
)
.project(
Arel::Nodes::NamedFunction.new(
'GROUP_CONCAT',
[
Arel::Nodes::NamedFunction.new(
'DISTINCT',
[tag_table[:id]],
),
],
),
),
)
end |
Fixes #925.
Fixes #1240.